<?php
class YouZiAction extends CommonAction {
    function _initialize() {
        $this->_inject_check(1);//调用过滤函数
		$this->_inject_check(0);//调用过滤函数
        $this->_checkUser();
        $this->_Admin_checkUser();//后台权限检测
        $this->_Config_name();//调用参数
        header("Content-Type:text/html; charset=utf-8");
        //D('Fck')->priceReturn(57);
        $rsOrid = '5005';
        //A('Gouwu')->createGouwu($rsOrid); 申请单
    }
    //================================================二级验证
    public function cody(){
        $UrlID  = (int) $_GET['c_id'];
        if (empty($UrlID)){
            $this->error('二级密码错误1!');
            exit;
        }
        if(!empty($_SESSION['user_pwd2'])){
            $url = __URL__."/codys/Urlsz/$UrlID";
            $this->_boxx($url);
            exit;
        }
        $cody   =  M ('cody');
        $list	=  $cody->where("c_id=$UrlID")->field('c_id')->find();
        if ($list){
            $this->assign('vo',$list);
            $this->display('Public:cody');
            exit;
        }else{
            $this->error('二级密码错误!');
            exit;
        }
    }
    //====================================二级验证后调转页面
    public function codys(){
        $Urlsz	= $_POST['Urlsz'];
        if(empty($_SESSION['user_pwd2'])){
            $pass	= $_POST['oldpassword'];
            $fck   =  M ('fck');
            if (!$fck->autoCheckToken($_POST)){
                $this->error('页面过期请刷新页面!');
                exit();
            }
            if (empty($pass)){
                $this->error('二级密码错误!');
                exit();
            }
            $where =  array();
            $where['id'] = $_SESSION[C('USER_AUTH_KEY')];
            $where['passopen'] = md5($pass);
            $list = $fck->where($where)->field('id')->find();
            if($list == false){
                $this->error('二级密码错误!');
                exit();
            }
            $_SESSION['user_pwd2'] = 1;
        }else{
            $Urlsz = $_GET['Urlsz'];
        }
        switch ($Urlsz){
            case 1;
                $_SESSION['UrlPTPass'] = 'MyssShenShuiPuTao';
                $bUrl = __URL__.'/auditMenber';//审核会员
                $this->_boxx($bUrl);
                break;
            case 2;
                $_SESSION['UrlPTPass'] = 'MyssGuanShuiPuTao';
                $bUrl = __URL__.'/adminMenber';//会员管理
                $this->_boxx($bUrl);
                break;
            case 3;
                $_SESSION['UrlPTPass'] = 'MyssPingGuoCP';
                $bUrl = __URL__.'/setParameter';//参数设置
                $this->_boxx($bUrl);
                break;
            case 4;
                $_SESSION['UrlPTPass'] = 'MyssPingGuo';
                $bUrl = __URL__.'/adminParameter';//比例设置
                $this->_boxx($bUrl);
                break;
            case 5;
                $_SESSION['UrlPTPass'] = 'MyssMiHouTao';
                $bUrl = __URL__.'/adminFinance';//拨出比例
                $this->_boxx($bUrl);
                break;
            case 6;
                $_SESSION['UrlPTPass'] = 'MyssGuanPaoYingTao';
                $bUrl = __URL__.'/adminCurrency';//提现管理
                $this->_boxx($bUrl);
                break;
            case 7;
                $_SESSION['UrlPTPass'] = 'MyssHaMiGua';
                $bUrl = __APP__.'/Backup/';//数据库管理
                $this->_boxx($bUrl);
                break;
            case 8;
                $_SESSION['UrlPTPass'] = 'MyssPiPa';
                $bUrl = __URL__.'/adminFinanceTable';//奖金查询
                $this->_boxx($bUrl);
                break;
            case 9;
                $_SESSION['UrlPTPass'] = 'MyssQingKong';
                $bUrl = __URL__.'/delTable';//清空数据
                $this->_boxx($bUrl);
                break;
            case 10;
                $_SESSION['UrlPTPass'] = 'MyssGuanXiGua';
                $bUrl = __URL__.'/adminAgents';//代理商管理
                $this->_boxx($bUrl);
                break;
            case 11;
                $_SESSION['UrlPTPass'] = 'MyssBaiGuoJS';
                $bUrl = __URL__.'/adminClearing';//奖金结算
                $this->_boxx($bUrl);
                break;
            case 12;
                $_SESSION['UrlPTPass'] = 'MyssGuanMangGuo';
                $bUrl = __URL__.'/adminCurrencyRecharge';//充值管理
                $this->_boxx($bUrl);
                break;
            case 13;
                $_SESSION['UrlPTPass'] = 'MyssGuansingle';
                $bUrl = __URL__.'/adminsingle';//加单管理
                $this->_boxx($bUrl);
                break;
            case 17;
                $_SESSION['UrlPTPass'] = 'MyssGuancash';
                $bUrl = __URL__.'/adminCash';//加单管理
                $this->_boxx($bUrl);
                break;
            case 18;
                $_SESSION['UrlPTPass'] = 'MyssMoneyFlows';
                $bUrl = __URL__.'/adminmoneyflows';//财务流向管理
                $this->_boxx($bUrl);
                break;
            case 19;
                $_SESSION['UrlPTPass'] = 'MyssadminMenberJL';
                $bUrl = __URL__.'/adminMenberJL';
                $this->_boxx($bUrl);
                break;
            case 21;
                $_SESSION['UrlPTPass'] = 'MyssGuanXiGuaUp';
                $bUrl = __URL__.'/adminUserUp';//升级管理
                $this->_boxx($bUrl);
                break;
            case 22;
                $_SESSION['UrlPTPass'] = 'MyssPingGuoCPB';
                $bUrl = __URL__.'/setParameter_B';
                $this->_boxx($bUrl);
                break;
            case 23;
                $_SESSION['UrlPTPass'] = 'MyssOrdersList';
                $bUrl = __URL__.'/OrdersList';//加单管理
                $this->_boxx($bUrl);
                break;
            case 24;
                $_SESSION['UrlPTPass'] = 'MyssWuliuList';
                $bUrl = __URL__.'/adminLogistics';//物流管理
                $this->_boxx($bUrl);
                break;
            case 25;
                $_SESSION['UrlPTPass'] = 'MyssGuanXiGuaJB';
                $bUrl = __URL__.'/adminJB';//金币中心管理
                $this->_boxx($bUrl);
                break;
            case 26;
                $_SESSION['UrlPTPass'] = 'MyssGuanChanPin';
                $bUrl = __URL__.'/pro_index';//产品管理
                $this->_boxx($bUrl);
                break;
            case 27;
                $_SESSION['UrlPTPass'] = 'MyssGuanzy';
                $bUrl = __URL__.'/admin_zy';//专营店管理
                $this->_boxx($bUrl);
                break;
            case 28;
                $_SESSION['UrlPTPass'] = 'MyssShenqixf';
                $bUrl = __URL__.'/adminXiaofei';//消费申请
                $this->_boxx($bUrl);
                break;
            case 29;
                $_SESSION['UrlPTPass'] = 'MyssJinji';
                $bUrl = __URL__.'/adminmemberJJ';//升级
                $this->_boxx($bUrl);
                break;
            case 30;
                $_SESSION['UrlPTPass'] = 'Myssadminlookfhall';
                $bUrl = __URL__.'/adminlookfhall';
                $this->_boxx($bUrl);
                break;
            case 31;
                $_SESSION['UrlPTPass'] = 'MyssAgentIis';
                $bUrl = __URL__.'/AgentIis';
                $this->_boxx($bUrl);
                break;
            
            default;
                $bUrl = __APP__;
                $this->_box(1,'二级密码已验证，无需重复操作！',$bUrl,1);
                break;
        }
    }

    //代理审核通过
    public function AgentTo(){
        $tabledb = $_REQUEST['tabledb'];
        $agent   = $_REQUEST['is_agent'];
        $fck = M('fck');
        $id  = $_SESSION[C('USER_AUTH_KEY')];
        $adminid = $fck->where("id='1'")->getField('id');
        if(!empty($tabledb) && $adminid>0){
            foreach($agent as $key=>$value){
                if(in_array($key,$tabledb)){
                    $re = $fck->where("id='".$key."'")->save(array("is_agent"=>$value,'shoplx'=>0));
                    D("Fck")->addencAdd($key['id'],$adminid,0,9,'代理审核通过','agent_use');
                }
            }
            $bUrl = __URL__.'/cody/c_id/31';
            $this->success("审核成功",$bUrl);
        }else{
            $this->error("请选择会员");
        }
    }
 //代理审核列表
    public function AgentIis(){
        //列表过滤器，生成查询Map对象
        if ($_SESSION['UrlPTPass'] == 'MyssAgentIis'){
            $fck = M('fck');
            $UserID = $_REQUEST['UserID'];
            $ss_type = (int) $_REQUEST['type'];
            $map = array();
            $uulv = (int)$_REQUEST['ulevel'];
            if(!empty($uulv)){
                $map['u_level'] = array('eq',$uulv);
            }
            $map['is_pay'] = array('egt',1);
            $map['shoplx'] = array('egt',1);
            //查询字段
            $field  = '*';
            //=====================分页开始==============================================
            import ( "@.ORG.ZQPage" );  //导入分页类
            $count = $fck->where($map)->count();//总页数
            $listrows = 20;//每页显示的记录数
            $page_where = 'UserID=' . $UserID. '&ulevel=' . $uulv ;//分页条件
            $Page = new ZQPage($count, $listrows, 1, 0, 3, $page_where);
            //===============(总页数,每页显示记录数,css样式 0-9)
            $show = $Page->show();//分页变量
            $this->assign('page',$show);//分页变量输出到模板
            $list = $fck->where($map)->field($field)->order('pdt desc,id desc')->page($Page->getPage().','.$listrows)->select();

            $HYJJ = '';
            $this->_getLevelConfirm($HYJJ,1);
            $this->assign("HYJJ",$HYJJ);
            $HYNM = '';
            $this->_levelConfirm($HYNM,1);
            $this->assign("HYNM",$HYNM);
            $Agent = '';
            $this->_getAgentConfirm($Agent,1);
            $this->assign("Agent",$Agent);

            $this->assign("uulv",$uulv);
            $this->assign("UserID",$UserID);
            $this->assign('list',$list);//数据输出到模板
            $this->display ();
            return;
        }else{
            $this->error('数据错误!');
            exit;
        }
    }
    //统计中心
    public function CountCenter(){
        //会员真实总数
        $fck = M('fck');
        $number = $fck->where('id>0')->count();
        $this->assign('number',$number);

        //每天新注册会员人数
        $time1 = strtotime(date("Y-m-d"));
        $time2 = strtotime(date("Y-m-d")) + 24*3600-1;
        $new = array();
        $new['is_pay'] = array('egt',1);
        $new['pdt']    = array('between',array($time1,$time2));
        $todayNewNumber = $fck->where($new)->count();
        $this->assign('todayNewNumber',$todayNewNumber);

        //每天申请的订单金额
        $chongzhi = M('chongzhi');
        $Recharge = array();
        $Recharge['stype'] = 1;
        $Recharge['rdt'] = array('between',array($time1,$time2));
        $RechargeMoney = $chongzhi->where($Recharge)->sum('epoint');
        if ($RechargeMoney==null)$RechargeMoney=0;
        $this->assign('RechargeMoney',$RechargeMoney);
//            echo M()->_sql();exit;
        //确认成功金额
        $RechargeSure = array();
        $RechargeSure['stype'] = 1;
        $RechargeSure['is_pay'] = 1;
        $RechargeSure['rdt'] = array('between',array($time1,$time2));
        $SureRechargeMoney = $chongzhi->where($RechargeSure)->sum('epoint');
        if ($SureRechargeMoney==null)$SureRechargeMoney=0;
        $this->assign('SureRechargeMoney',$SureRechargeMoney);

        //所有已确认总金额
        $All = array();
        $All['stype'] = 1;
        $All['is_pay'] = 1;
        $AllMoney = $chongzhi->where($All)->sum('epoint');
        if ($AllMoney==null)$AllMoney=0;
        $this->assign('AllMoney',$AllMoney);

        //没交易结束的金额（还要分红收益的金额）
        $FHing = array();
        $FHing['is_pay'] = 1;
        $FHing['stype'] = 1;
        $FHing['get_fh'] = 0;
        $FHingMoney = $chongzhi->where($FHing)->sum('epoint');
        if ($FHingMoney==null)$FHingMoney=0;
        $this->assign('FHingMoney',$FHingMoney);

        $this->display();

    }

    //============================================会员升级页面显示
    public function admin_level($GPid=0){
        //列表过滤器，生成查询Map对象
        if ($_SESSION['UrlPTPass'] == 'MyssGuanUplevel'){
            $fck = M('fck');
            $UserID = $_POST['UserID'];
            if (!empty($UserID)){
                import ( "@.ORG.KuoZhan" );  //导入扩展类
                $KuoZhan = new KuoZhan();
                if ($KuoZhan->is_utf8($UserID) == false){
                    $UserID = iconv('GB2312','UTF-8',$UserID);
                }
                unset($KuoZhan);
                $where['nickname'] = array('like',"%".$UserID."%");
                $where['user_id'] = array('like',"%".$UserID."%");
                $where['_logic']    = 'or';
                $map['_complex']    = $where;
                $UserID = urlencode($UserID);
            }
            $map['sel_level'] = array('lt',90);

            //查询字段
            $field  = 'id,user_id,nickname,bank_name,bank_card,user_name,user_address,user_tel,rdt,f4,cpzj,pdt,u_level,sel_level';
            //=====================分页开始==============================================
            import ( "@.ORG.ZQPage" );  //导入分页类
            $count = $fck->where($map)->count();//总页数
            $listrows = C('ONE_PAGE_RE');//每页显示的记录数
            $page_where = 'UserID=' . $UserID;//分页条件
            $Page = new ZQPage($count, $listrows, 1, 0, 3, $page_where);
            //===============(总页数,每页显示记录数,css样式 0-9)
            $show = $Page->show();//分页变量
            $this->assign('page',$show);//分页变量输出到模板
            $list = $fck->where($map)->field($field)->order('rdt desc')->page($Page->getPage().','.$listrows)->select();

            $HYJJ = '';
            $this->_levelConfirm($HYJJ,1);

            $this->assign('list',$list);//数据输出到模板
            //=================================================

            $this->display ('admin_level');
        }else{
            $this->error('数据错误!');
            exit;
        }
    }
    //========================================数据库管理
    public function adminManageTables(){
        if ($_SESSION['UrlPTPass'] == 'MyssHaMiGua'){
            $Url =__ROOT__.'/HaMiGua/';
            $_SESSION['shujukuguanli!12312g@#$%^@#$!@#$~!@#$'] = md5("^&%#hdgfhfg$@#$@gdfsg13123123!@#!@#");
            $this ->_boxx($Url);
        }
    }
    //============================================审核会员
    public function auditMenber($GPid=0){
        //列表过滤器，生成查询Map对象
        if ($_SESSION['UrlPTPass'] == 'MyssShenShuiPuTao'){
            $fck = M('fck');
            
            $UserID = $_REQUEST['UserID'];
            if (!empty($UserID)){
                import ( "@.ORG.KuoZhan" );  //导入扩展类
                $KuoZhan = new KuoZhan();
                if ($KuoZhan->is_utf8($UserID) == false){
                    $UserID = iconv('GB2312','UTF-8',$UserID);
                }
                unset($KuoZhan);
                $where['nickname'] = array('like',"%".$UserID."%");
                $where['user_id'] = array('like',"%".$UserID."%");
                $where['_logic']    = 'or';
                $map['_complex']    = $where;
                $UserID = urlencode($UserID);
            }
            $map['is_pay'] = array('eq',0);
            $map['is_agent'] = array('eq',0);

            //查询字段
            $field  = '*';
            //=====================分页开始==============================================
            import ( "@.ORG.ZQPage" );  //导入分页类
            $count = $fck->where($map)->count();//总页数
            $listrows = C('ONE_PAGE_RE');//每页显示的记录数
            $page_where = 'UserID=' . $UserID;//分页条件
            $Page = new ZQPage($count, $listrows, 1, 0, 3, $page_where);
            //=================================================(总页数,每页显示记录数,css样式 0-9)
            $show = $Page->show();//分页变量
            $this->assign('page',$show);//分页变量输出到模板
            $list = $fck->where($map)->field($field)->order('is_pay,id,rdt desc')->page($Page->getPage().','.$listrows)->select();


            $HYJJ = '';
            $this->_levelConfirm($HYJJ,1);
            $this->assign('voo',$HYJJ);//会员级别
            $HYNM = '';
            $this->_getLevelConfirm($HYNM,1);
            $this->assign('HYNM',$HYNM);//会员级别
            $this->assign("UserID",$UserID);
            $this->assign('list',$list);//数据输出到模板
            $this->display ('auditMenber');
        }else{
            $this->error('数据错误!');
            exit;
        }
    }
    public function auditMenberData() {
        if ($_SESSION['UrlPTPass'] == 'MyssShenShuiPuTao' ){
            //查看会员详细信息
            $fck = M ( 'fck' );
            $ID = (int) $_GET['PT_id'];
            //判断获取数据的真实性 是否为数字 长度
            if (strlen($ID) > 11){
                $this->error ('数据错误!');
                exit;
            }
            $where = array();
            $where['id'] = $ID;
            $field = '*';
            $vo = $fck ->where($where)->field($field)->find();
            if ($vo){
                $this->assign ( 'vo', $vo );
                $this->display ();
            }else{
                $this->error ('数据错误!');
                exit;
            }
        }else{
            $this->error ('数据错误!');
            exit;
        }
    }
    public function auditMenberData2() {
        if ($_SESSION['UrlPTPass'] == 'MyssShenShuiPuTao' ){
            //查看会员详细信息
            $fck = M ( 'fck' );
            $ID = (int) $_GET['PT_id'];
            //判断获取数据的真实性 是否为数字 长度
            if (strlen($ID) > 11){
                $this->error ('数据错误!');
                exit;
            }
            $where = array();
            $where['id'] = $ID;
            $field = '*';
            $vo = $fck ->where($where)->field($field)->find();
            if ($vo){
                $this->assign ( 'vo', $vo );
                $this->display ();
            }else{
                $this->error ('数据错误!');
                exit;
            }
        }else{
            $this->error ('数据错误!');
            exit;
        }
    }
    public function auditMenberData2AC() {
        if ($_SESSION['UrlPTPass'] == 'MyssShenShuiPuTao' ){

            $fck = M ('fck');
            $data = array();

            $where['id'] = (int) $_POST['id'];
            $rs = $fck -> where('is_pay = 0') -> find($where['id']);
            if(!$rs){
                $this->error ('非法操作!');
                exit;
            }

            $data['nickname'] = $_POST['NickName'];
            $rs = $fck -> where($data) -> find();
            if($rs){
                if($rs['id'] != $where['id']){
                    $this->error ('该会员名已经存在!');
                    exit;
                }
            }

            $data['bank_name'] = $_POST['BankName'];
            $data['bank_card'] = $_POST['BankCard'];
            $data['user_name'] = $_POST['UserName'];
            $data['bank_province'] = $_POST['BankProvince'];
            $data['bank_city'] = $_POST['BankCity'];
            $data['user_code'] = $_POST['UserCode'];
            $data['bank_address'] = $_POST['BankAddress'];
            $data['user_address'] = $_POST['UserAddress'];
            $data['user_post'] = $_POST['UserPost'];
            $data['user_tel'] = $_POST['UserTel'];
            $data['bank_province'] = $_POST['BankProvince'];
            $data['is_lock'] = $_POST['isLock'];

            $fck->where($where)->data($data)->save();
            $bUrl = __URL__.'/auditMenberData2/PT_id/'.$where['id'];
            $this->_box(1,'修改会员信息！',$bUrl,1);

        }else{
            $this->error ('数据错误!');
            exit;
        }
    }
    public function auditMenberAC(){
        //处理提交按钮
        $action = $_POST['action'];
        //获取复选框的值
        $PTid = $_POST['tabledb'];
        if (!isset($PTid) || empty($PTid)){
            $bUrl = __URL__.'/auditMenber';
            $this->_box(0,'请选择会员！',$bUrl,1);
            exit;
        }
        switch ($action){
            case '激活会员';
                $this->_auditMenberOpenUser($PTid);
                break;
            case '设为空单';
                $this->_auditMenberOpenNull($PTid);
                break;
            case '删除会员';
                $this->_auditMenberDelUser($PTid);
                break;
            case '申请通过';
                $this->_AdminLevelAllow($PTid);
                break;
            case '拒绝通过';
                $this->_AdminLevelNo($PTid);
                break;
            default;
                $bUrl = __URL__.'/auditMenber';
                $this->_box(0,'没有该会员！',$bUrl,1);
                break;
        }
    }


    //审核会员升级-通过
    private function _AdminLevelAllow($PTid=0){
        if ($_SESSION['UrlPTPass'] == 'MyssGuanUplevel'){
            $fck = M ('fck');
            $where = array();
            $where['id'] = array ('in',$PTid);
            $where['sel_level'] = array('lt',90);
            $vo = $fck ->where($where)->field('id,sel_level')->select();
            foreach($vo as $voo){
                $where = array();
                $data  = array();
                $where['id'] = $voo['id'];
                $data['u_level']   = $voo['sel_level'];
                $data['sel_level'] = 98;
                $fck -> where($where) -> data($data) -> save();
            }

            $bUrl = __URL__.'/admin_level';
            $this->_box(1,'会员升级通过！',$bUrl,1);
        }else{
            $this->error ('数据错误!');
            exit;
        }

    }

    //审核会员升级-拒绝
    private function _AdminLevelNo($PTid=0){
        if ($_SESSION['UrlPTPass'] == 'MyssGuanUplevel'){
            $fck = M ('fck');
            $where = array();
            $where['id'] = array ('in',$PTid);
            $where['sel_level'] = array('lt',90);
            $vo = $fck ->where($where)->field('id')->select();
            foreach($vo as $voo){
                $where = array();
                $data  = array();
                $where['id'] = $voo['id'];
                $data['sel_level'] = 97;
                $fck -> where($where) -> data($data) -> save();
            }

            $bUrl = __URL__.'/admin_level';
            $this->_box(1,'拒绝会员升级！',$bUrl,1);
        }else{
            $this->error ('数据错误!');
            exit;
        }

    }

    //===============================================设为空单
    private function _auditMenberOpenNull($PTid=0){
        if ($_SESSION['UrlPTPass'] == 'MyssShenShuiPuTao'){
            $fck = D ('Fck');
            $where = array();
            if (!$fck->autoCheckToken($_POST)){
                $this->error('页面过期，请刷新页面！');
                exit;
            }
            $ID = $_SESSION[C('USER_AUTH_KEY')];
            $where['id'] = array ('in',$PTid);
            $where['is_pay'] = 0;
            $field = "id,u_level,re_id,cpzj,re_path,user_id,p_path,p_level,shop_id,f4";
            $vo = $fck ->where($where)->order('rdt asc')->field($field)->select();
            $nowdate = strtotime(date('c'));
            $nowday=strtotime(date('Y-m-d'));
            $nowmonth = date('m');

            foreach($vo as $voo){
                $ppath = $voo['p_path'];
                //上级未开通不能开通下级员工
                $frs_where['is_pay'] = array('eq',0);
                $frs_where['id'] = $voo['father_id'];
                $frs = $fck -> where($frs_where) -> find();
                if($frs){
                    $this->error('开通失败，上级未开通');
                    exit;
                }

                $nnrs = $fck->where('is_pay>0')->field('n_pai')->order('n_pai desc')->find();
                $mynpai = ((int)$nnrs['n_pai'])+1;

                $data = array();
                $data['is_pay'] = 2;
                $data['pdt'] = $nowdate;
                $data['open'] = 1;
                $data['get_date'] = $nowday;
                $data['fanli_time'] = $nowday;
                $data['n_pai'] = $mynpai;

//				$data['n_pai'] = $max_p;
//				$data['x_pai'] = $myppp;
                //开通会员
                $result = $fck->where('id='.$voo['id'])->save($data);
                unset($data,$varray);

            }
            unset($fck,$where,$field,$vo,$nowday);
            $bUrl = __URL__.'/auditMenber';
            $this->_box(1,'设为空单！',$bUrl,1);
            exit;

        }else{
            $this->error('错误！');
            exit;
        }
    }

    //双轨小公排
    public function gongpaixtsmall($uid){
        $fck = M ('fck');
        $mouid=$uid;
        $field = 'id,user_id,p_level,p_path,u_pai';
        $where = 'is_pay>0 and (p_path like "%,'.$mouid.',%" or id='.$mouid.')';

        $re_rs = $fck ->where($where)->order('p_level asc,u_pai asc')->field($field)->select();
        $fck_where = array();
        foreach($re_rs as $vo){
            $faid=$vo['id'];
            $fck_where['is_pay']   = array('egt',0);
            $fck_where['father_id']   = $faid;
            $count = $fck->where($fck_where)->count();
            if ( is_numeric($count) == false){
                $count = 0;
            }
            if ($count<2){
                $father_id=$vo['id'];
                $father_name=$vo['user_id'];
                $TreePlace=$count;
                $p_level=$vo['p_level']+1;
                $p_path=$vo['p_path'].$vo['id'].',';
                $u_pai=$vo['u_pai']*2+$TreePlace;

                $arry=array();
                $arry['father_id']=$father_id;
                $arry['father_name']=$father_name;
                $arry['treeplace']=$TreePlace;
                $arry['p_level']=$p_level;
                $arry['p_path']=$p_path;
                $arry['u_pai']=$u_pai;
                return $arry;
                break;
            }
        }
    }

    //三轨小公排
    public function gongpaixtsmall_three($uid){

        $fck = M ('fck');
        $mouid=$uid;
        $field = 'id,user_id,p_level,p_path,u_pai';
        $where = 'is_pay>0 and (p_path like "%,'.$mouid.',%" or id='.$mouid.')';

        $re_rs = $fck ->where($where)->order('p_level asc,u_pai asc')->field($field)->select();
        $fck_where = array();
        foreach($re_rs as $vo){
            $faid=$vo['id'];
            $fck_where['is_pay']   = array('egt',0);
            $fck_where['father_id']   = $faid;
            $count = $fck->where($fck_where)->count();
            if ( is_numeric($count) == false){
                $count = 0;
            }
            if ($count<3){
                $father_id=$vo['id'];
                $father_name=$vo['user_id'];
                $TreePlace=$count;
                $p_level=$vo['p_level']+1;
                $p_path=$vo['p_path'].$vo['id'].',';
                $u_pai=$vo['u_pai']*3+$TreePlace-1;

                $arry=array();
                $arry['father_id']=$father_id;
                $arry['father_name']=$father_name;
                $arry['treeplace']=$TreePlace;
                $arry['p_level']=$p_level;
                $arry['p_path']=$p_path;
                $arry['u_pai']=$u_pai;
                return $arry;
                break;
            }
        }
    }

    //找出最后一个子账号
    public function last_x_num($id){
        $fck=M('fck');
        $count=$fck->where('x_num='.$id)->count();
        if($count){
            return $fck->where('x_num='.$id)->field('id,user_id,re_path,re_name,re_id,re_level,get_ceng')->order('get_ceng desc')->find();
        }else{
            return $fck->where('id='.$id)->field('id,user_id,re_path,re_name,re_id,re_level,get_ceng')->find();
        }
    }
//	开通子帐号
    public function _OpenFormyself($id,$dan){
        if($dan<1) return;
        $fck = D ('Fck');

        $myrs=$fck->where('id='.$id)->find();
        $uLevel =$dan;

        $fee = M('fee');
        $fee_rs = $fee->field('s12,s9,i5')->find();

        $s12 = $fee_rs['s12'];//互助奖
        $s9 =$fee_rs['s9'];
        $nowdate = strtotime(date('c'));
        $nowday=strtotime(date('Y-m-d'));
        //会员级别
        $count=$dan;
        for($i=0;$i<$count;$i++) {
            $data = array();
            //推荐人 start
            $re_info=$this->last_x_num($id);
            $data['re_path'] = $re_info['re_path'].$re_info['id'].',';  //推薦路徑
            $data['re_id'] = $re_info['id'];                              //推薦人ID
            $data['re_name'] = $re_info['user_id'];                       //推薦人帳號
            $data['re_level'] = $re_info['re_level'] + 1;                 //代數(絕對層數)
            $data['get_ceng'] = $re_info['get_ceng'] + 1;                 //代數(絕對層數)
            //推荐人start
            $fck->execute('update __TABLE__ set re_nums=re_nums+1,re_f4=re_f4+1 where id='.$re_info['id']);
            //推荐人 end

            $data['user_id'] = $myrs['user_id'].(string)($re_info['get_ceng'] + 1);
            $data['bind_account'] = '3333';
            $data['last_login_ip'] = '';                            //最後登錄IP
            $data['verify'] = '0';
            $data['status'] = 1;                             //狀態(?)
            $data['type_id'] = '0';
            $data['last_login_time'] = time();                        //最後登錄時間
            $data['login_count'] = 0;                             //登錄次數
            $data['info'] = '信息';
            $data['name'] = '名稱';
            $data['password'] = $myrs['password'];
            $data['passopen'] = $myrs['passopen'];
            $data['pwd1'] = $myrs['pwd1'];
            $data['pwd2'] = $myrs['pwd2'];

            $data['wenti'] = $myrs['wenti'];
            $data['wenti_dan'] = $myrs['wenti_dan'];

            $data['bank_name'] = $myrs['bank_name'];
            $data['bank_card'] = $myrs['bank_card'];
            $data['user_name'] = $myrs['user_name'];
            $data['nickname'] = $myrs['nickname'];
            $data['bank_province'] = $myrs['bank_province'];
            $data['bank_city'] = $myrs['bank_city'];
            $data['bank_address'] = $myrs['bank_address'];
            //$data['user_post']           = $myrs['user_post'];		   //
            $data['user_code'] = $myrs['user_code'];
            $data['user_address'] = $myrs['user_address'];
            $data['email'] = $myrs['email'];
            $data['qq'] = $myrs['qq'];
            $data['user_tel'] = $myrs['user_tel'];
            $data['rdt'] = time();
            $data['u_level'] = $uLevel + 1;
            $data['y_level'] = $myrs['y_level'];
            $data['cpzj'] = $s9;
            $data['f4'] = 1;
            $data['wlf'] = 0;

            $data['is_pay'] = 1;
            $data['rdt'] = time();
            $data['pdt'] = time();
            $data['open'] = 0;
            $data['get_date'] = $nowday;
            $data['fanli_time'] = $nowday;

            $data['x_num'] = $myrs['id'];

            //  开通以后就是小公排
            $data['father_id'] = 1;
            $data['father_name'] = 1;
            $data['treeplace'] = 1;
            $data['p_level'] = 1;
            $data['p_path'] =1;
            $data['u_pai'] = 1;

            $resss = $fck->add($data);
            echo $fck->getDbError();
            unset($data);
        }
        unset($fck,$where);
    }

    //===============================================开通会员
    private function _auditMenberOpenUser($PTid=0){
        if ($_SESSION['UrlPTPass'] == 'MyssShenShuiPuTao'){
            $adminid = $_SESSION[C('USER_AUTH_KEY')];
            $fck = D ('Fck');
            $shouru = M ('shouru');
            $blist = M('blist');
            $fee = M('fee');
            $Guzhi = A('Guzhi');
            $where = array();
            $where['id'] = array ('in',$PTid);
            $where['is_pay'] = 0;
            $where['is_agent'] = 0;
            $field = "*";
            $vo = $fck->where($where)->field($field)->order('id asc')->select();
            $nowdate = strtotime(date('c'));
            $nowday = strtotime(date('Y-m-d'));
            $nowmonth = date('m');
            foreach($vo as $voo){
                //给推荐人添加推荐人数或单数
                // $fck->query("UPDATE __TABLE__ SET `re_nums`=re_nums+1,re_f4=re_f4+".$voo['f4']." where `id`=".$voo['re_id']);
                // $point = $this->gongpaixtsmall_three($voo['receive_name']);
                $data['b1'] = 0;
                $data['is_pay'] = 1;
                $data['is_fenh'] = 0;
                $data['pdt'] = time();
                //开通会员
                $result = $fck->where('id='.$voo['id'])->save($data);
                //$fck->addencAdd($voo['id'],$adminid,$voo['cpzj'],12,'激活会员','agent_use');  不用记录激活积分
                unset($data,$varray);

                //$fck->priceOpen($voo['id']);   //正式会员开通奖

                $create_gouwu = A('Gouwu')->createGouwu($voo);
                if(!$create_gouwu) {
                    $bUrl = __URL__.'/auditMenber';
                    $this->error('激活会员创建物流信息失败！',$bUrl);
                }
                 /*$data = array();
                 $data['uid'] = $voo['id'];
                 $data['user_id'] = $voo['user_id'];
                 $data['in_money'] = $voo['cpzj'];
                 $data['in_time'] = time();
                 $data['in_bz'] = "新会员加入";
                 $shouru->add($data);*/
                 unset($data);
            }
            $bUrl = __URL__.'/auditMenber';
            $this->success('激活会员成功！',$bUrl);
            exit;
        }else{
            $this->error('错误！');
            exit;
        }
    }

    private function _auditMenberDelUser($PTid=0){
        //删除会员
        if ($_SESSION['UrlPTPass'] == 'MyssShenShuiPuTao'){
            $fck = M ('fck');
            $ispay = M('ispay');
            $where['is_pay'] = 0;
//			$where['id'] = array ('in',$PTid);
            foreach($PTid as $voo){
                $rs = $fck -> find($voo);
                if($rs){
                    $whe['father_name'] = $rs['user_id'];
                    $rss = $fck -> where($whe) -> find();
                    if($rss){
                        $bUrl = __URL__.'/auditMenber';
                        $this -> error('该 '. $rs['user_id'] .' 会员有下级会员，不能删除！');
                        exit;
                    }else{
                        $where['id'] = $voo;
                        $a= $fck->where($where)->delete();
                        $bUrl = __URL__.'/auditMenber';
                        $this->_box(1,'删除会员！',$bUrl,1);
                    }
                }else{
                    $this->error('错误!');
                }
            }

//			$rs = $fck->where($where)->delete();
//			if ($rs){
//				$bUrl = __URL__.'/auditMenber';
//				$this->_box(1,'删除会员！',$bUrl,1);
//				exit;
//			}else{
//				$bUrl = __URL__.'/auditMenber';
//				$this->_box(0,'删除会员！',$bUrl,1);
//				exit;
//			}
        }else{
            $this->error('错误!');
        }
    }

    public function adminMenber($GPid=0){
        //列表过滤器，生成查询Map对象
        if ($_SESSION['UrlPTPass'] == 'MyssGuanShuiPuTao'){
            $fck = M('fck');
            $fckldj = M('fckldj');
            $UserID = $_REQUEST['UserID'];
            $ss_type = (int) $_REQUEST['type'];

            $map = array();
            if (!empty($UserID)){
                import ( "@.ORG.KuoZhan" );  //导入扩展类
                $KuoZhan = new KuoZhan();
                if ($KuoZhan->is_utf8($UserID) == false){
                    $UserID = iconv('GB2312','UTF-8',$UserID);
                }
                unset($KuoZhan);
                $where['nickname'] = array('like',"%".$UserID."%");
                $where['user_id'] = array('like',"%".$UserID."%");
                $where['_logic']    = 'or';
                $map['_complex']    = $where;
                $UserID = urlencode($UserID);
            }
            $uulv = (int)$_REQUEST['ulevel'];
            if(!empty($uulv)){
                $map['u_level'] = array('eq',$uulv);
            }
            $map['is_pay'] = array('egt',1);
            

            //附加查询
            if ($_POST['other']==1){
                //今天注册的
                $ago_day = strtotime(date("Y-m-d"));
                $ago_day1 = strtotime(date("Y-m-d")) + 24*3600;
                $map['rdt'] = array('between',array($ago_day,$ago_day1));
                $this->assign('other',$_POST['other']);
            }

            //查询字段
            $field  = '*';
            //=====================分页开始==============================================
            import ( "@.ORG.ZQPage" );  //导入分页类
            $count = $fck->where($map)->count();//总页数
            // $listrows = C('ONE_PAGE_RE');//每页显示的记录数
            $listrows = 20;//每页显示的记录数
            $page_where = 'UserID=' . $UserID. '&ulevel=' . $uulv ;//分页条件
            $Page = new ZQPage($count, $listrows, 1, 0, 3, $page_where);
            //===============(总页数,每页显示记录数,css样式 0-9)
            $show = $Page->show();//分页变量
            $this->assign('page',$show);//分页变量输出到模板
            $list = $fck->where($map)->field($field)->order('pdt desc,id desc')->page($Page->getPage().','.$listrows)->select();
            foreach($list as $key => $value){
                $list[$key]['is_jtsy'] = isshouyi($value['cpzj'],$value['b1']);
            }
            $HYJJ = '';
            $this->_getLevelConfirm($HYJJ,1);
            $this->assign("HYJJ",$HYJJ);
            $HYNM = '';
            $this->_levelConfirm($HYNM,1);
            $this->assign("HYNM",$HYNM);
            $Agent = '';
            $this->_getAgentConfirm($Agent,1);
            $this->assign("Agent",$Agent);
            $this->assign("uulv",$uulv);
            $this->assign("UserID",$UserID);
            $this->assign('list',$list);//数据输出到模板
            //=================================================
            $title = '会员管理';
            $this->assign('title',$title);
            $this->display ('adminMenber');
            return;
        }else{
            $this->error('数据错误!');
            exit;
        }
    }

    public function adminlookfh(){
        if ($_SESSION['UrlPTPass'] == 'MyssGuanShuiPuTao'){

            $uid = (int)$_GET['uid'];
            if(empty($uid)){
                $this->error('数据错误!');
                exit;
            }
            $fenhong = M('fenhong');
            $where = array();
            $where['uid'] = array('eq',$uid);

            //查询字段
            $field  = '*';
            //=====================分页开始==============================================
            import ( "@.ORG.ZQPage" );  //导入分页类
            $count = $fenhong->where($where)->count();//总页数
            $listrows = C('ONE_PAGE_RE');//每页显示的记录数
            $page_where = '';//分页条件
            $Page = new ZQPage($count, $listrows, 1, 0, 3, $page_where);
            //===============(总页数,每页显示记录数,css样式 0-9)
            $show = $Page->show();//分页变量
            $this->assign('page',$show);//分页变量输出到模板
            $list = $fenhong->where($where)->field($field)->order('f_num asc,id asc')->page($Page->getPage().','.$listrows)->select();
            $this->assign('list',$list);//数据输出到模板
            //=================================================
            $this->display();

        }else{
            $this->error('数据错误!');
            exit;
        }
    }

    public function adminlookfhall(){
        if ($_SESSION['UrlPTPass'] == 'Myssadminlookfhall'){

            $fenhong = M('fenhong');
            $where = array();
            //查询字段
            $field  = '*';
            //=====================分页开始==============================================
            import ( "@.ORG.ZQPage" );  //导入分页类
            $count = $fenhong->where($where)->count();//总页数
            $listrows = C('ONE_PAGE_RE');//每页显示的记录数
            $page_where = '';//分页条件
            $Page = new ZQPage($count, $listrows, 1, 0, 3, $page_where);
            //===============(总页数,每页显示记录数,css样式 0-9)
            $show = $Page->show();//分页变量
            $this->assign('page',$show);//分页变量输出到模板
            $list = $fenhong->where($where)->field($field)->order('f_num asc,id asc')->page($Page->getPage().','.$listrows)->select();
            $this->assign('list',$list);//数据输出到模板
            //=================================================
            $this->display();

        }else{
            $this->error('数据错误!');
            exit;
        }
    }

    public function premAdd(){
        if ($_SESSION['UrlPTPass'] == 'MyssGuanShuiPuTao'){
            $id = (int) $_GET['id'];
            $table = M ('fck');
            $rs = $table -> field('id,is_boss,prem') ->find($id);
            if ($rs){
                $ars = array();
                $arr = explode(',',$rs['prem']);
                for ($i=1;$i<=30;$i++){
                    if (in_array($i,$arr)){
                        $ars[$i] = "checked";
                    }else{
                        $ars[$i] = "";
                    }
                }
                $this->assign('ars',$ars);
                $this->assign('rs',$rs);
                $title = '修改权限';
            }else{
                $title = '添加权限';
            }

            $this->assign('title',$title);
            $this->display('premAdd');
        }else{
            $this->error('权限错误!');
        }
    }

    public function premAddSave(){
        if ($_SESSION['UrlPTPass'] == 'MyssGuanShuiPuTao'){
            $id = (int) $_POST['id'];
            if ($id == 1 && $_SESSION[C('USER_AUTH_KEY')] != 1){
                $this->error('不能修改该会员的权限!');
                exit;
            }
            $table = M ('fck');
            $is_boss = $_POST['is_boss'];
            $boss = $_POST['isBoss'];
            $arr = ',';
            if (is_array($is_boss)){
                foreach ($is_boss as $vo){
                    $arr .= $vo.',';
                }
            }
            $data = array();
            $data['is_boss'] = $boss;
            $data['prem'] = $arr;
            $data['id'] = $id;
//            if ($id == 1){
//            	$this->error('不能修改最高会员！');
//            }
            $table->save($data);
            $title = '修改权限';
            $bUrl = __URL__.'/adminMenber';
            $this->_box(1,$title,$bUrl,2);
        }else{
            $this->error('权限错误!');
        }
    }

    //显示劳资详细
    public function BonusShow($GPid=0){
        if ($_SESSION['UrlPTPass'] == 'MyssGuanShuiPuTao'){
            $hi = M ('history');

            $where = array();
            $where['Uid']   = $_REQUEST['PT_id'];
            $where['type'] = 19;

            $list = $hi -> where($where) -> select();
            $this -> assign('list',$list);
            $this->display ('BonusShow');
        }else{
            $this->error('数据错误!');
            exit;
        }
    }


    public function adminuserData() {
            //查看会员详细信息
            $fck = M ( 'fck' );
            $ID = (int) $_GET['PT_id'];
            $adminid = $fck->where("id='1'")->getField("id");
            //判断获取数据的真实性 是否为数字 长度
            if (strlen($ID) > 15 && $adminid<0){
                $this->error ('数据错误!');
                exit;
            }
            $where = array();
            //查询条件
            $where['id'] = $ID;
            $field ='*';
            $vo = $fck ->where($where)->field($field)->find();
            if ($vo){
                $HYJJ = '';
                $this->_getLevelConfirm($HYJJ,1);
                $this->assign("HYJJ",$HYJJ);
                $HYNM = '';
                $this->_levelConfirm($HYNM,1);
                $this->assign("HYNM",$HYNM);
                $Agent = '';
                $this->_getAgentConfirm($Agent,1);
                $this->assign("Agent",$Agent);
                $this->assign('rs',$vo);
                $this->display("user_card");
            }else{
                $this->error ('数据错误!');
                exit;
            }
    }

    public function adminuserDataSave() {

            $fck     =   M('fck');
            if(!$fck->autoCheckToken($_POST)) {
                $this->error('页面过期，请刷新页面！');
            }
            $ID = (int) $_POST['ID'];
            $frs_list = $fck->where("re_path like ('%".$ID."%'")->select();
            $frs      = $fck->where("id='".$ID."'")->find();
            if(!empty($frs_lis) && $frs["re_name"]!=$_POST['re_name']){
                $this->error('拥有下级会员不能修改推荐人');
            }
            $fee = M('fee');
            $fee_rs = $fee->where("id=1")->field("s2")->find();
            $s2 = explode("|",$fee_rs["s2"]);
            $level = $_POST['level']-1;
            $res = $fck->where("user_id='".$_POST['re_name']."'")->find();
            $re_path = $res["re_path"].$res['id'].',';//推荐路径
            $data = array();
            $data['pwd1']             = trim($_POST['pwd1']);      //一级密码不加密
            $data['pwd2']             = trim($_POST['pwd2']);
            
            $data['password']         = md5(trim($_POST['pwd1'])); //一级密码加密
            $data['passopen']         = md5(trim($_POST['pwd2']));

            $data['user_id']          = $_POST['user_id'];
            $data['name']             = $_POST['name'];
            $data['re_name']          = $res['user_id'];
            $data['re_id']            = $res['id'];
            $data['re_path']          = $re_path;
            $data['user_name']        = $_POST['user_name'];
            $data['bank_name']        = $_POST['bank_name'];
            $data['bank_card']        = $_POST['bank_card'];
            $data['account']          = $_POST['account'];
            $data['user_tel']         = $_POST['user_tel'];
            $data['u_level']          = $_POST['level'];
            $data['is_agent']         = $_POST['agent'];
            $data['shoplx']           = 0;
            $data['cpzj']             = $s2[$level];
            $data['zjj']              = $_POST['zjj'];
            $result =   $fck->where("id='".$ID."'")->save($data);
            unset($data);
            if($result) {
                $bUrl = __URL__.'/adminMenber';
                $this->_box(1,'资料修改成功！',$bUrl,1);
                exit;
            }else{
                $bUrl = __URL__.'/adminMenber';
                $this->_box(0,'资料修改失败！',$bUrl,1);
            }
     
    }
    //后台添加会员
    public function adminuserDataVied() {
            //查看会员详细信息
            $fck = M ('fck');
            $adminid = $fck->where("id='1'")->getField("id");
            //判断获取数据的真实性 是否为数字 长度
            if (strlen($ID) > 15 && $adminid<0){
                $this->error ('数据错误!');
                exit;
            }
            $HYJJ = '';
            $this->_getLevelConfirm($HYJJ,1);
            $this->assign("HYJJ",$HYJJ);
            $HYNM = '';
            $this->_levelConfirm($HYNM,1);
            $this->assign("HYNM",$HYNM);
            $Agent = '';
            $this->_getAgentConfirm($Agent,1);
            $this->assign("Agent",$Agent);

            $this->display();
            
    }
    //添加会员
    public function adminuserDataAdd() {

            $fck     =   M('fck');
            if(!$fck->autoCheckToken($_POST)) {
                $this->error('页面过期，请刷新页面！');
            }
            $user_id = $_POST['user_id'];

            $frs      = $fck->where("user_id='".$user_id."'")->find();
            if(!empty($frs)){
                $this->error('账号已被注册');
            }
            if(empty($_POST['user_id'])){
                $this->error('账号不能空');
            }
            if(empty($_POST['pwd1'])){
                $this->error('一级密码不能空');
            }
            if(empty($_POST['pwd2'])){
                $this->error('二级密码不能空');
            }
            
            if(empty($_POST['re_name'])){
                $this->error('推荐人不能空');
            }
            $res = $fck->where("user_id='".$_POST['re_name']."'")->find();
            if(empty($res)){
                $this->error('推荐人不存在');
            }
            $fee = M('fee');
            $fee_rs = $fee->where("id=1")->field("s2")->find();
            $s2 = explode("|",$fee_rs['s2']);
            $level = $_POST['level']-1;
            $re_path = $res["re_path"].$res['id'].',';//推荐路径
            $data = array();
            $data['pwd1']             = trim($_POST['pwd1']);      //一级密码不加密
            $data['pwd2']             = trim($_POST['pwd2']);
            $data['password']         = md5(trim($_POST['pwd1'])); //一级密码加密
            $data['passopen']         = md5(trim($_POST['pwd2']));
            $data['user_id']          = $_POST['user_id'];
            $data['name']             = $_POST['name'];
            $data['re_name']          = $res['user_id'];
            $data['re_id']            = $res['id'];
            $data['re_path']          = $re_path;
            $data['user_name']        = $_POST['user_name'];
            $data['bank_name']        = $_POST['bank_name'];
            $data['bank_card']        = $_POST['bank_card'];
            $data['account']          = $_POST['account'];
            $data['user_tel']         = $_POST['user_tel'];
            $data['u_level']          = $_POST['level'];
            $data['is_agent']         = $_POST['agent'];
            $data['shoplx']           = 0;
            $data['is_pay']           = 1;
            $data['cpzj']             = $s2[$level];
            $data['rdt']              = time();
            $data['pdt']              = time();
            $result =   $fck->add($data);
            unset($data);
            if($result) {
                $bUrl = __URL__.'/adminMenber';
                $this->_box(1,'添加成功',$bUrl,1);
                exit;
            }else{
                $bUrl = __URL__.'/adminMenber';
                $this->_box(0,'添加失败！',$bUrl,1);
            }
     
    }
    public function slevel() {
        if ($_SESSION['UrlPTPass'] == 'MyssGuanShuiPuTao' || $_SESSION['UrlPTPass'] == 'MyssGuanXiGua' || $_SESSION['UrlPTPass'] == 'MyssGuansingle'){
            //查看会员详细信息
            $fck = M ( 'fck' );
            $ID = (int) $_GET['PT_id'];
            //判断获取数据的真实性 是否为数字 长度
            if (strlen($ID) > 15){
                $this->error ('数据错误!');
                exit;
            }
            $where = array();
            //查询条件
            //$where['ReID'] = $_SESSION[C('USER_AUTH_KEY')];
            $where['id'] = $ID;
            $field ='*';
            $vo = $fck ->where($where)->field($field)->find();
            if ($vo){
                $this->assign ( 'vo', $vo );
                $this->display ();
            }else{
                $this->error ('数据错误!');
                exit;
            }
        }else{
            $this->error ('数据错误!');
            exit;
        }
    }
    public function slevelsave() {  //升级保存数据
        if ($_SESSION['UrlPTPass'] == 'MyssGuanShuiPuTao' || $_SESSION['UrlPTPass'] == 'MyssGuanXiGua' || $_SESSION['UrlPTPass'] == 'MyssGuansingle'){
            //查看会员详细信息
            $fck = D ('Fck');
            $fee = M ('fee');
            $ID = (int) $_POST['ID'];
            $slevel = (int) $_POST['slevel'];  //升级等级

            //判断获取数据的真实性 是否为数字 长度
            if (strlen($ID) > 15 or $ID <= 0){
                $this->error ('数据错误!');
                exit;
            }

            $fee_rs = $fee -> find(1);
            if( $slevel <= 0 or $slevel >= 7){
                $this->error('升级等级错误！');
                exit;
            }

            $where = array();
            //查询条件
            //$where['ReID'] = $_SESSION[C('USER_AUTH_KEY')];
            $where['id'] = $ID;
            $field ='*';
            $vo = $fck ->where($where)->field($field)->find();
            if($vo){
                switch($slevel){  //通过注册等级从数据库中找出注册金额及认购单数
                    case 1:
                        $cpzj = $fee_rs['uf1'];  //注册金额
                        $F4 = $fee_rs['jf1'];    //自身认购单数
                        break;
                    case 2:
                        $cpzj = $fee_rs['uf2'];
                        $F4 = $fee_rs['jf2'];
                        break;
                    case 3:
                        $cpzj = $fee_rs['uf3'];
                        $F4 = $fee_rs['jf3'];
                        break;
                    case 4:
                        $cpzj = $fee_rs['uf4'];
                        $F4 = $fee_rs['jf4'];
                        break;
                    case 5:
                        $cpzj = $fee_rs['uf5'];
                        $F4 = $fee_rs['jf5'];
                        break;
                    case 6:
                        $cpzj = $fee_rs['uf6'];
                        $F4 = $fee_rs['jf6'];
                        break;
                }

                $number = $F4 - $vo['f4'];  //升级所需单数差
                $data = array();
                $data['u_level'] = $slevel;  // 升级等级
                $data['cpzj'] = $cpzj;     // 注册金额
                $data['f4'] = $F4;       // 自身认购单数
                $fck -> where($where) -> data($data) -> save();

                $fck->xiangJiao_lr($ID,$number);//住上统计单数

                $bUrl = __URL__.'/adminMenber';
                $this->_box(1,'会员升级！',$bUrl,1);
                exit;
            }else{
                $this->error ('数据错误!');
                exit;
            }
        }else{
            $this->error ('数据错误!');
            exit;
        }
    }
    public function adminMenberAC(){
        //处理提交按钮
        $action = $_POST['action'];
        //获取复选框的值
        $PTid = $_POST['tabledb'];
        if (!isset($PTid) || empty($PTid)){
            $bUrl = __URL__.'/adminMenber';
            $this->_box(0,'请选择会员！',$bUrl,1);
            exit;
        }
        switch ($action){
            case '开启会员';
                $this->_adminMenberOpen($PTid);
                break;
            case '锁定会员';
                $this->_adminMenberLock($PTid);
                break;
            case '奖金提现';
                $this->adminMenberCurrency($PTid);
                break;
            case '开启奖金';
                $this->adminMenberFenhong($PTid);
                break;
            case '删除会员';
                $this->adminMenberDel($PTid);
                break;
            case '关闭奖金';
                $this->_Lockfenh($PTid);
                break;
            case '开启期限';
                $this->_OpenQd($PTid);
                break;
            case '关闭期限';
                $this->_LockQd($PTid);
                break;
            case '开启分红奖';
                $this->_OpenFh($PTid);
                break;
            case '关闭分红奖';
                $this->_LockFh($PTid);
                break;
            case '奖金转注册币';
                $this->adminMenberZhuan($PTid);
                break;
            case '设为代理中心';
                $this->_adminMenberAgent($PTid);
                break;
            case '取消代理中心';
                $this->_adminMenberAgentcancel($PTid);
                break;
            case '特殊账号';
                $this->_adminMenber_bad($PTid);
                break;
            case '取消特殊账号';
                $this->_adminMenber_not_bad($PTid);
                break;
            case '设为代理商';
                $this->_adminMenberJB($PTid);
                break;
            case '取消代理商';
                $this->adminMenberJBcancel($PTid);
                break;
            case '设为物流管理';
                $this->_adminMenberWL($PTid);
                break;
            case '设为财务管理';
                $this->_adminMenberCw($PTid);
            case '取消管理员';
                $this->adminMenberWLcancel($PTid);
                break;
            case '修改天数';
                $this->adminMenberupdatefhday($PTid);
                break;
            case '添加会员';
                $this->adminMenberupdatefhday($PTid);
                break;
            default;
                $bUrl = __URL__.'/adminMenber';
                $this->_box(0,'没有该会员！',$bUrl,1);
                break;
        }
    }

    public function adminMenberDL(){

        if($_SESSION['UrlPTPass'] == 'MyssGuanShuiPuTao'){
            $fck = M ('fck');
            $result=$fck->execute('update __TABLE__ set agent_cash=agent_cash+agent_use,agent_use=0 where is_pay>0');

            $bUrl = __URL__.'/adminMenber';
            $this->_box(1,'转换会员奖金为注册币！',$bUrl,1);

        }else{
            $this->error('错误2!');
        }
    }

    public function adminMenberZhuan($PTid=0){

        if($_SESSION['UrlPTPass'] == 'MyssGuanShuiPuTao'){
            $fck = M ('fck');
            $where['id'] = array ('in',$PTid);
            $rs = $fck->where($where)->field('id')->select();
            foreach($rs as $vo){
                $myid=$vo['id'];
                $fck->execute('update __TABLE__ set agent_cash=agent_cash+agent_use,agent_use=0 where is_pay>0 and id='.$myid.'');
            }
            unset($fck,$where,$rs,$myid,$result);
            $bUrl = __URL__.'/adminMenber';
            $this->_box(1,'转换会员奖金为注册币！',$bUrl,1);

        }else{
            $this->error('错误2!');
        }
    }

    private function _adminMenberJB($PTid=0){
        if($_SESSION['UrlPTPass'] == 'MyssGuanShuiPuTao'){
            $fck = M ('fck');
            $where['id'] = array ('in',$PTid);
            $where['is_pay'] = array('gt',0);
            $where['is_jb'] = array('eq',0);
            $rs = $fck->where($where)->setField('is_jb','1');
            if ($rs){
                $bUrl = __URL__.'/adminMenber';
                $this->_box(1,'设为代理商成功！',$bUrl,1);
                exit;
            }else{
                $bUrl = __URL__.'/adminMenber';
                $this->_box(0,'设为代理商失败！',$bUrl,1);
                exit;
            }
        }else{
            $this->error('错误！');
            exit;
        }
    }

    public function adminMenberJBcancel($PTid=0){

        if($_SESSION['UrlPTPass'] == 'MyssGuanShuiPuTao'){
            $fck = M ('fck');
            $where['id'] = array ('in',$PTid);
            $rs = $fck->where($where)->field('id')->select();
            foreach($rs as $vo){
                $myid=$vo['id'];
                $fck->execute('update __TABLE__ set is_jb=0 where is_pay>0 and is_jb>0 and id='.$myid.'');
            }
            unset($fck,$where,$rs,$myid,$result);
            $bUrl = __URL__.'/adminMenber';
            $this->_box(1,'取消代理商成功！',$bUrl,1);

        }else{
            $this->error('错误2!');
        }
    }

    private function _adminMenberCw($PTid=0){
        if($_SESSION['UrlPTPass'] == 'MyssGuanShuiPuTao'){
            $fck = M ('fck');
            $where['id'] = array ('in',$PTid);
            $where['is_pay'] = array('gt',0);
            $where['is_aa'] = array('eq',0);
            $rs = $fck->where($where)->setField('is_aa','1');
            if ($rs){
                $bUrl = __URL__.'/adminMenber';
                $this->_box(1,'设为物流管理成功！',$bUrl,1);
                exit;
            }else{
                $bUrl = __URL__.'/adminMenber';
                $this->_box(0,'设为物流管理失败！',$bUrl,1);
                exit;
            }
        }else{
            $this->error('错误！');
            exit;
        }
    }

    private function _adminMenberWL($PTid=0){
        if($_SESSION['UrlPTPass'] == 'MyssGuanShuiPuTao'){
            $fck = M ('fck');
            $where['id'] = array ('in',$PTid);
            $where['is_pay'] = array('gt',0);
            $where['is_aa'] = array('eq',0);
            $rs = $fck->where($where)->setField('is_aa','2');
            if ($rs){
                $bUrl = __URL__.'/adminMenber';
                $this->_box(1,'设为物流管理成功！',$bUrl,1);
                exit;
            }else{
                $bUrl = __URL__.'/adminMenber';
                $this->_box(0,'设为物流管理失败！',$bUrl,1);
                exit;
            }
        }else{
            $this->error('错误！');
            exit;
        }
    }

    public function adminMenberWLcancel($PTid=0){

        if($_SESSION['UrlPTPass'] == 'MyssGuanShuiPuTao'){
            $fck = M ('fck');
            $where['id'] = array ('in',$PTid);
            $rs = $fck->where($where)->field('id')->select();
            foreach($rs as $vo){
                $myid=$vo['id'];
                $fck->execute('update __TABLE__ set is_aa=0 where is_pay>0 and is_aa>0 and id='.$myid.'');
            }
            unset($fck,$where,$rs,$myid,$result);
            $bUrl = __URL__.'/adminMenber';
            $this->_box(1,'取消管理员成功！',$bUrl,1);

        }else{
            $this->error('错误2!');
        }
    }

    private function adminMenberDel($PTid=0){
        if($_SESSION['UrlPTPass'] == 'MyssGuanShuiPuTao'){
            $fck = M ('fck');
            $times = M ('times');
            $bonus = M ('bonus');
            $history = M ('history');
            $chongzhi = M ('chongzhi');
            $gouwu = M ('gouwu');
            $tiqu = M ('tiqu');
            $zhuanj = M ('zhuanj');

            foreach($PTid as $voo){
                $rs = $fck -> find($voo);
                if($rs){
                    $id = $rs['id'];
                    $whe['father_id'] = $rs['id'];
                    $con = $fck ->where($whe)->count();
                    if($id == 1){
                        $bUrl = __URL__.'/adminMenber';
                        $this -> error('该 '. $rs['user_id'] .' 不能删除！');
                        exit;
                    }
                    if($con==2){
                        $bUrl = __URL__.'/adminMenber';
                        $this -> error('该 '. $rs['user_id'] .' 会员有下级会员，不能删除！');
                        exit;
                    }
                    if($con==1){
                        $this->set_Re_Path($id);
                        $this->set_P_Path($id);
                    }
                    $where = array();
                    $where['id'] = $voo;
                    $map['uid'] = $voo;
                    $bonus->where($map) -> delete();
                    $history->where($map) -> delete();
                    $chongzhi->where($map) -> delete();
                    $times->where($map) -> delete();
                    $tiqu->where($map) -> delete();
                    $zhuanj->where($map) -> delete();
                    $gouwu->where($map) -> delete();
                    $fck->where($where)->delete();
                    $bUrl = __URL__.'/adminMenber';
                    $this->_box(1,'删除会员！',$bUrl,1);
                }
            }
        }else{
            $this->error('错误!');
        }
    }


    public function set_Re_Path($id){
        $fck = M("fck");
        $frs = $fck -> find($id);

        $r_rs = $fck -> find($frs['re_id']);
        $xr_rs = $fck ->where("re_id=".$id)-> select();
        foreach($xr_rs as $xr_vo){
            $re_Level = $r_rs['re_level'] + 1;
            $re_path = $r_rs['re_path'].$r_rs['id'].',';
            $fck->execute("UPDATE __TABLE__ SET re_id=".$r_rs['id'].",re_name='".$r_rs['user_id']."',re_path='".$re_path."',re_level=".$re_Level." where `id`= ".$xr_vo['id']);
            //修改推荐路径
            $f_where = array();
            $f_where['re_path'] = array('like','%,'.$xr_vo['id'].',%');
            $ff_rs = $fck->where($f_where)->order('re_level asc')->select();
            $r_where = array();
            foreach($ff_rs as $fvo){
                $r_where['id'] = $fvo['re_id'];
                $sr_rs = $fck->where($r_where)->find();
                $r_pLevel = $sr_rs['re_level'] + 1;
                $r_re_path = $sr_rs['re_path'].$sr_rs['id'].',';
                $fck->execute("UPDATE __TABLE__ SET re_path='".$r_re_path."',re_level=".$r_pLevel." where `id`= ".$fvo['id']);
            }
        }
    }

    public function set_P_Path($id){
        $fck = M("fck");
        $frs = $fck -> find($id);

        $r_rs = $fck -> find($frs['father_id']);
        $xr_rs = $fck ->where("father_id=".$id)-> find();
        if($xr_rs){
            $p_level = $r_rs['p_level'] + 1;
            $p_path = $r_rs['p_path'].$r_rs['id'].',';
            $fck->execute("UPDATE __TABLE__ SET treeplace=".$frs['treeplace'].",father_id=".$r_rs['id'].",father_name='".$r_rs['user_id']."',p_path='".$p_path."',p_level=".$p_level." where `id`= ".$xr_rs['id']);
            //修改推荐路径
            $f_where = array();
            $f_where['p_path'] = array('like','%,'.$xr_rs['id'].',%');
            $ff_rs = $fck->where($f_where)->order('p_level asc')->select();
            $r_where = array();
            foreach($ff_rs as $fvo){
                $r_where['id'] = $fvo['father_id'];
                $sr_rs = $fck->where($r_where)->find();
                $p_level = $sr_rs['p_level'] + 1;
                $p_path = $sr_rs['p_path'].$sr_rs['id'].',';
                $fck->execute("UPDATE __TABLE__ SET p_path='".$p_path."',p_level=".$p_level." where `id`= ".$fvo['id']);
            }
        }
    }

    public function jiandan($Pid=0,$DanShu=1,$pdt,$t_rs){
        //========================================== 往上统计单数
        $fck = M ('fck');
        $where = array();
        $where['id'] = $Pid;
        $field = 'treeplace,father_id,pdt';
        $vo = $fck ->where($where)->field($field)->find();
        if ($vo){
            $Fid = $vo['father_id'];
            $TPe = $vo['treeplace'];
            if($pdt>$t_rs){
                if ($TPe == 0 && $Fid > 0){
                    $fck->execute("update __TABLE__ Set `l`=l-$DanShu, `benqi_l`=benqi_l-$DanShu where `id`=".$Fid);
                }elseif($TPe == 1 && $Fid > 0){
                    $fck->execute("update __TABLE__ Set `r`=r-$DanShu, `benqi_r`=benqi_r-$DanShu  where `id`=".$Fid);
                }
            }else{
                if ($TPe == 0 && $Fid > 0){
                    $fck->execute("update __TABLE__ Set `l`=l-$DanShu where `id`=".$Fid);
                }elseif($TPe == 1 && $Fid > 0){
                    $fck->execute("update __TABLE__ Set `r`=r-$DanShu  where `id`=".$Fid);
                }
            }

            if ($Fid > 0) $this->jiandan($Fid,$DanShu,$pdt,$t_rs);
        }
        unset($where,$field,$vo,$pdt,$t_rs);
    }

    private function adminMenberFenhong($PTid=0){
        if($_SESSION['UrlPTPass'] == 'MyssGuanShuiPuTao'){
            $fck = M ('fck');
            $where['id'] = array ('in',$PTid);
            $where['is_pay'] = array('gt',0);
            $rs = $fck->where($where)->setField('is_fenh','0');
            if ($rs){
                $bUrl = __URL__.'/adminMenber';
                $this->_box(1,'开启奖金成功！',$bUrl,1);
                exit;
            }else{
                $bUrl = __URL__.'/adminMenber';
                $this->_box(0,'开启奖金失败！',$bUrl,1);
                exit;
            }
        }else{
            $this->error('错误！');
            exit;
        }
    }

    private function _Lockfenh($PTid=0){
        //锁定会员
        if ($_SESSION['UrlPTPass'] == 'MyssGuanShuiPuTao'){
            $fck = M ('fck');
            $where['is_pay'] = array('egt',1);
            $where['_string'] = 'id>1';
            $where['id'] = array ('in',$PTid);
            $rs = $fck->where($where)->setField('is_fenh','1');

            if ($rs){
                $bUrl = __URL__.'/adminMenber';
                $this->_box(1,'关闭奖金成功！',$bUrl,1);
                exit;
            }else{
                $bUrl = __URL__.'/adminMenber';
                $this->_box(0,'关闭奖金失败！',$bUrl,1);
                exit;
            }
        }else{
            $this->error('错误!');
        }
    }

    //开启会员
    private function _adminMenberOpen($PTid=0){
        if ($_SESSION['UrlPTPass'] == 'MyssGuanShuiPuTao'){
            $fck = M ('fck');
            $where['id'] = array ('in',$PTid);
            $data['is_pay'] = 1;
            $rs = $fck->where($where)->setField('is_lock','0');
            if ($rs){
                $bUrl = __URL__.'/adminMenber';
                $this->success('开启会员！',$bUrl);
                exit;
            }else{
                $bUrl = __URL__.'/adminMenber';
                $this->error('开启失败！',$bUrl);
                exit;
            }
        }else{
            $this->error('错误！');
            exit;
        }
    }
    private function _adminMenberLock($PTid=0){
        //锁定会员
        if ($_SESSION['UrlPTPass'] == 'MyssGuanShuiPuTao'){
            $fck = M ('fck');
            
            $where['is_boss'] = 0;
            $where['id'] = array ('in',$PTid);
            $rs = $fck->where($where)->setField('is_lock','1');
            if ($rs){
                $bUrl = __URL__.'/adminMenber';
                $this->success('锁定会员！',$bUrl);
                exit;
            }else{
                $bUrl = __URL__.'/adminMenber';
                $this->error('锁定失败！',$bUrl);
                exit;
            }
        }else{
            $this->error('错误!');
        }
    }

    //设为报单中心
    private function _adminMenberAgent($PTid=0){
        if ($_SESSION['UrlPTPass'] == 'MyssGuanShuiPuTao'){
            $fck = M ('fck');
            $where['id'] = array ('in',$PTid);
            $where['is_agent'] = array ('lt',2);
            $rs2 = $fck->where($where)->setField('adt',mktime());
            $rs1 = $fck->where($where)->setField('is_agent','2');
            if ($rs1){
                $bUrl = __URL__.'/adminMenber';
                $this->_box(1,'设置代理中心成功！',$bUrl,1);
                exit;
            }else{
                $bUrl = __URL__.'/adminMenber';
                $this->_box(0,'设置代理中心失败！',$bUrl,1);
                exit;
            }
        }else{
            $this->error('错误！');
            exit;
        }
    }
    //取消报单中心
    private function _adminMenberAgentcancel($PTid=0){
        if ($_SESSION['UrlPTPass'] == 'MyssGuanShuiPuTao'){
            $fck = M ('fck');
            $where['id'] = array ('in',$PTid);
            $where['is_agent'] = array ('eq',2);
            $rs2 = $fck->where($where)->setField('adt',mktime());
            $rs1 = $fck->where($where)->setField('is_agent','0');
            if ($rs1){
                $bUrl = __URL__.'/adminMenber';
                $this->_box(1,'取消代理中心成功！',$bUrl,1);
                exit;
            }else{
                $bUrl = __URL__.'/adminMenber';
                $this->_box(0,'取消代理中心失败！',$bUrl,1);
                exit;
            }
        }else{
            $this->error('错误！');
            exit;
        }
    }
    private function _adminMenber_bad($PTid=0){
        if ($_SESSION['UrlPTPass'] == 'MyssGuanShuiPuTao'){
            $fck = M ('fck');
            $where['id'] = array ('in',$PTid);
            $rs1 = $fck->where($where)->setField('is_lockqd','1');//is_lockqd字段用作表示特殊账号了
            if ($rs1){
                $bUrl = __URL__.'/adminMenber';
                $this->_box(1,'设置特殊账号成功！',$bUrl,1);
                exit;
            }else{
                $bUrl = __URL__.'/adminMenber';
                $this->_box(0,'设置特殊账号失败！',$bUrl,1);
                exit;
            }
        }else{
            $this->error('错误！');
            exit;
        }
    }
    private function _adminMenber_not_bad($PTid=0){
        if ($_SESSION['UrlPTPass'] == 'MyssGuanShuiPuTao'){
            $fck = M ('fck');
            $where['id'] = array ('in',$PTid);
            $rs1 = $fck->where($where)->setField('is_lockqd','0');//is_lockqd字段用作表示特殊账号了
            if ($rs1){
                $bUrl = __URL__.'/adminMenber';
                $this->_box(1,'取消特殊账号成功！',$bUrl,1);
                exit;
            }else{
                $bUrl = __URL__.'/adminMenber';
                $this->_box(0,'取消特殊账号失败！',$bUrl,1);
                exit;
            }
        }else{
            $this->error('错误！');
            exit;
        }
    }

    //开启分红奖
    private function _OpenFh($PTid=0){
        if ($_SESSION['UrlPTPass'] == 'MyssGuanShuiPuTao'){
            $fck = M ('fck');
            $nowday = strtotime(date('Y-m-d'));
            $where['is_lockfh'] = array('egt',1);
            $where['_string'] = 'id>1';
            $where['id'] = array ('in',$PTid);
            $varray = array(
                'is_lockfh'=>'0',
                'fanli_time'=>$nowday
            );
            $rs = $fck->where($where)->setField($varray);
            if ($rs){
                $bUrl = __URL__.'/adminMenber';
                $this->_box(1,'开启分红奖成功！',$bUrl,1);
                exit;
            }else{
                $bUrl = __URL__.'/adminMenber';
                $this->_box(0,'开启分红奖失败！',$bUrl,1);
                exit;
            }
        }else{
            $this->error('错误!');
        }
    }
    //关闭分红奖
    private function _LockFh($PTid=0){
        if ($_SESSION['UrlPTPass'] == 'MyssGuanShuiPuTao'){
            $fck = M ('fck');
            $where['is_lockfh'] = array('egt',0);
            $where['_string'] = 'id>1';
            $where['id'] = array ('in',$PTid);
            $rs = $fck->where($where)->setField('is_lockfh','1');

            if ($rs){
                $bUrl = __URL__.'/adminMenber';
                $this->_box(1,'关闭分红奖成功！',$bUrl,1);
                exit;
            }else{
                $bUrl = __URL__.'/adminMenber';
                $this->_box(0,'关闭分红奖失败！',$bUrl,1);
                exit;
            }
        }else{
            $this->error('错误!');
        }
    }

    public function adminMenberUP(){
        //会员升级
        if ($_SESSION['UrlPTPass'] == 'MyssGuanShuiPuTao'){
            $fck = M ('fck');
            $PTid = (int) $_GET['UP_ID'];
            $rs = $fck -> find($PTid);

            if(!$rs){
                $this->error('非法操作！');
                exit;
            }

            switch($rs['u_level']){
                case 1:
                    $fck->query("UPDATE `xt_fck` SET u_level=2,b12=2000 where id=".$PTid);
                    break;
                case 2:
                    $fck->query("UPDATE `xt_fck` SET u_level=3,b12=4000 where id=".$PTid);
                    break;
            }

            unset($fck,$PTid);
            $bUrl = __URL__.'/adminMenber';
            $this->_box(1,'晋升！',$bUrl,1);
        }else{
            $this->error('错误!');
        }
    }


    //=================================================管理员帮会员提现处理
    public function adminMenberCurrency($PTid=0){
        if ($_SESSION['UrlPTPass'] == 'MyssGuanShuiPuTao'){
            $fck = M ('fck');
            $where = array();//
            $tiqu = M ('tiqu');
            //查询条件
            $where['id'] = array('in',$PTid);
            $where['agent_use'] = array('egt',100);
            $field ='id,user_id,agent_use,bank_name,bank_card,user_name';
            $fck_rs = $fck ->where($where)->field($field)->select();

            $data = array();
            $tiqu_where = array();
            $eB = 0.02;//提现税收
            $nowdate = strtotime(date('c'));
            foreach ($fck_rs as $vo){
                $is_qf = 0;//区分上次有没有提现
                $ePoints = 0;
                $ePoints = $vo['agent_use'];

                $tiqu_where['uid'] = $vo['id'];
                $tiqu_where['is_pay'] = 0;
                $trs = $tiqu ->where($tiqu_where)->field('id')->find();
                if ($trs){
                    $is_qf = 1;
                }
                //提现税收
//				if ($ePoints >= 10 && $ePoints <= 100){
//					$ePoints1 = $ePoints - 2;
//				}else{
//					$ePoints1 = $ePoints - $ePoints * $eB;//(/100);
//				}

                if ($is_qf == 0){
                    $fck->query("UPDATE `xt_fck` SET `zsq`=zsq+agent_use,`agent_use`=0 where `id`=".$vo['id']);
                    //开始事务处理
                    $data['uid']            = $vo['id'];
                    $data['user_id']        = $vo['user_id'];
                    $data['rdt']            = $nowdate;
                    $data['money']          = $ePoints;
                    $data['money_two']      = $ePoints;
                    $data['is_pay']         = 1;
                    $data['user_name']      = $vo['user_name'];
                    $data['bank_name']      = $vo['bank_name'];
                    $data['bank_card']      = $vo['bank_card'];
                    $tiqu->add($data);
                }
            }
            unset($fck,$where,$tiqu,$field,$fck_rs,$data,$tiqu_where,$eB,$nowdate);
            $bUrl = __URL__.'/adminMenber';
            $this->_box(1,'奖金提现！',$bUrl,1);
            exit;
        }else{
            $this->error('错误!');
            exit;
        }
    }


    //===============================================消费管理
    public function adminXiaofei(){
        if ($_SESSION['UrlPTPass'] == 'MyssShenqixf'){
            $xiaof = M ('xiaof');
            $UserID = $_POST['UserID'];
            if (!empty($UserID)){
                $map['user_id'] = array('like',"%".$UserID."%");
            }

            $field  = '*';
            //=====================分页开始==============================================
            import ( "@.ORG.ZQPage" );  //导入分页类
            $count = $xiaof->where($map)->count();//总页数
            $listrows = C('ONE_PAGE_RE');//每页显示的记录数
            $page_where = 'UserID=' . $UserID;//分页条件
            $Page = new ZQPage($count, $listrows, 1, 0, 3, $page_where);
            //===============(总页数,每页显示记录数,css样式 0-9)
            $show = $Page->show();//分页变量
            $this->assign('page',$show);//分页变量输出到模板
            $list = $xiaof->where($map)->field($field)->order('id desc')->page($Page->getPage().','.$listrows)->select();
            $this->assign('list',$list);//数据输出到模板
            //=================================================

            $this->display('adminXiaofei');
        }else{
            $this->error('错误!');
            exit;
        }
    }
    //处理消费
    public function adminXiaofeiAC(){
        //处理提交按钮
        $action = $_POST['action'];
        //获取复选框的值
        $PTid = $_POST['tabledb'];
        $fck = M ('fck');
//	    if (!$fck->autoCheckToken($_POST)){
//            $this->error('页面过期，请刷新页面！');
//            exit;
//        }
        if (empty($PTid)){
            $bUrl = __URL__.'/adminXiaofei';
            $this->_box(0,'请选择！',$bUrl,1);
            exit;
        }
        switch ($action){
            case '确认':
                $this->_adminXiaofeiConfirm($PTid);
                break;
            case '删除':
                $this->_adminXiaofeiDel($PTid);
                break;
            default:
                $bUrl = __URL__.'/adminXiaofei';
                $this->_box(0, '没有该记录！', $bUrl,1);
                break;
        }
    }

    //====================================================确认消费
    private function _adminXiaofeiConfirm($PTid){
        if ($_SESSION['UrlPTPass'] == 'MyssShenqixf'){
            $xiaof = M ('xiaof');
            $fck = M('fck');//
            $where = array();
            $where['is_pay'] = 0;               //未审核的申请
            $where['id'] = array ('in',$PTid);  //所有选中的会员ID
            $rs = $xiaof->where($where)->select();  //tiqu表要通过的申请记录数组
            $history = M('history');
            $data = array();
            $fck_where = array();
            $nowdate = strtotime(date('c'));
            foreach($rs as $rss){
                //开始事务处理
                $fck->startTrans();
                //明细表
                $data['uid']           = $rss['uid'];
                $data['user_id']       = $rss['user_id'];
                $data['action_type']   = '重复消费';
                $data['pdt']           = $nowdate;
                $data['epoints']       = -$rss['money'];
                $data['bz']            = '重复消费';
                $data['did']           = 0;
                $data['allp']          = 0;
                $history->create();
                $rs1 = $history->add($data);
                if ($rs1){
                    //提交事务
                    $xiaof->execute("UPDATE __TABLE__ set `is_pay`=1 where `id`=".$rss['id']);
                    $fck->commit();
                }else{
                    //事务回滚：
                    $fck->rollback();
                }
            }
            unset($xiaof,$fck,$where,$rs,$history,$data,$nowdate,$fck_where);
            $bUrl = __URL__.'/adminXiaofei';
            $this->_box(1,'确认消费成功！',$bUrl,1);
        }else{
            $this->error('错误!');
            exit;
        }
    }
    //删除消费
    private function _adminXiaofeiDel($PTid){
        if ($_SESSION['UrlPTPass'] == 'MyssShenqixf'){
            $xiaof = M ('xiaof');
            $where = array();
            $where['is_pay'] = 0;
            $where['id'] = array ('in',$PTid);
            $trs = $xiaof->where($where)->select();
            $fck = M ('fck');
            foreach ($trs as $vo){
                $fck->execute("UPDATE __TABLE__ SET agent_cash=agent_cash+{$vo['money']} WHERE id={$vo['uid']}");
            }
            $rs = $xiaof->where($where)->delete();
            if ($rs){
                $bUrl = __URL__.'/adminXiaofei';
                $this->_box(1,'删除成功！',$bUrl,1);
                exit;
            }else{
                $bUrl = __URL__.'/adminXiaofei';
                $this->_box(1,'删除成功！',$bUrl,1);
                exit;
            }
        }else{
            $this->error('错误!');
            exit;
        }
    }


    public function financeDaoChu_ChuN(){
        //导出excel
        set_time_limit(0);

        header("Content-Type:   application/vnd.ms-excel");
        header("Content-Disposition:   attachment;   filename=Cashier.xls");
        header("Pragma:   no-cache");
        header("Content-Type:text/html; charset=utf-8");
        header("Expires:   0");

        $m_page = (int)$_GET['p'];
        if(empty($m_page)){
            $m_page=1;
        }

        $times = M ('times');
        $Numso = array();
        $Numss = array();
        $map = 'is_count=0';
        //查询字段
        $field   = '*';
        import ( "@.ORG.ZQPage" );  //导入分页类
        $count = $times->where($map)->count();//总页数
        $listrows = C('PAGE_LISTROWS')  ;//每页显示的记录数
        $s_p = $listrows*($m_page-1)+1;
        $e_p = $listrows*($m_page);

        $title   =   "当期出纳 第".$s_p."-".$e_p."条 导出时间:".date("Y-m-d   H:i:s");



        echo   '<table   border="1"   cellspacing="2"   cellpadding="2"   width="50%"   align="center">';
        //   输出标题
        echo   '<tr   bgcolor="#cccccc"><td   colspan="6"   align="center">'   .   $title   .   '</td></tr>';
        //   输出字段名
        echo   '<tr  align=center>';
        echo   "<td>期数</td>";
        echo   "<td>结算时间</td>";
        echo   "<td>当期收入</td>";
        echo   "<td>当期支出</td>";
        echo   "<td>当期盈利</td>";
        echo   "<td>拨出比例</td>";
        echo   '</tr>';
        //   输出内容

        $rs = $times->where($map)->order(' id desc')->find();
        $Numso['0'] = 0;
        $Numso['1'] = 0;
        $Numso['2'] = 0;
        if ($rs){
            $eDate = strtotime(date('c'));  //time()
            $sDate = $rs['benqi'] ;//时间

            $this->MiHouTaoBenQi($eDate, $sDate, $Numso, 0);
        }


        $page_where = '';//分页条件
        $Page = new ZQPage($count, $listrows, 1, 0, 3, $page_where);
        //===============(总页数,每页显示记录数,css样式 0-9)
        $show = $Page->show();//分页变量
        $list = $times ->where($map)->field($field)->order('id desc')->page($Page->getPage().','.$listrows)->select();

//		dump($list);exit;

        $occ = 1;
        $Numso['1'] = $Numso['1']+$Numso['0'];
        $Numso['3'] = $Numso['3']+$Numso['0'];
        $maxnn=0;
        foreach ($list as $Roo){

            $eDate          = $Roo['benqi'];//本期时间
            $sDate          = $Roo['shangqi'];//上期时间
            $Numsd          = array();
            $Numsd[$occ][0] = $eDate;
            $Numsd[$occ][1] = $sDate;

            $this->MiHouTaoBenQi($eDate,$sDate,$Numss,1);
            //$Numoo = $Numss['0'];   //当期收入
            $Numss[$occ]['0'] = $Numss['0'];
            $Dopp  = M ('bonus');
            $field = '*';
            $where = " s_date>= '".$sDate."' And e_date<= '".$eDate."' ";
            $rsc   = $Dopp->where($where)->field($field)->select();
            $Numss[$occ]['1'] = 0;
            $nnn=0;
            foreach ($rsc as $Roc){
                $nnn++;
                $Numss[$occ]['1'] += $Roc['b0'] ;  //当期支出
                $Numb2[$occ]['1'] += $Roc['b1'];
                $Numb3[$occ]['1'] += $Roc['b2'];
                $Numb4[$occ]['1'] += $Roc['b3'];
                //$Numoo          += $Roc['b9'];//当期收入
            }
            $maxnn+=$nnn;
            $Numoo              = $Numss['0'];//当期收入
            $Numss[$occ]['2']   = $Numoo - $Numss[$occ]['1'];   //本期赢利
            $Numss[$occ]['3']   = substr( floor(($Numss[$occ]['1'] / $Numoo) * 100) , 0 ,3);  //本期拔比
            $Numso['1']        += $Numoo;  //收入合计
            $Numso['2']        += $Numss[$occ]['1'];           //支出合计
            $Numso['3']        += $Numss[$occ]['2'];           //赢利合计
            $Numso['4']         = substr( floor(($Numso['2'] / $Numso['1']) * 100) , 0 ,3);  //总拔比
            $Numss[$occ]['4']   = substr( ($Numb2[$occ]['1'] / $Numoo) * 100 , 0 ,4);  //小区奖金拔比
            $Numss[$occ]['5']   = substr( ($Numb3[$occ]['1'] / $Numoo) * 100 , 0 ,4);  //互助基金拔比
            $Numss[$occ]['6']   = substr( ($Numb4[$occ]['1'] / $Numoo) * 100 , 0 ,4); //管理基金拔比
            $Numss[$occ]['7']	= $Numb2[$occ]['1'];//小区奖金
            $Numss[$occ]['8'] 	= $Numb3[$occ]['1'] ;  //互助基金
            $Numss[$occ]['9'] 	= $Numb4[$occ]['1'];//管理基金
            $Numso['5']        += $Numb2[$occ]['1'];  //小区奖金合计
            $Numso['6']        += $Numb3[$occ]['1'];  //互助基金合计
            $Numso['7']        += $Numb4[$occ]['1'];  //管理基金合计
            $Numso['8']         = substr( ($Numso['5'] / $Numso['1']) * 100 , 0 ,4);  //小区奖金总拔比
            $Numso['9']         = substr( ($Numso['6'] / $Numso['1']) * 100 , 0 ,4);  //互助基金总拔比
            $Numso['10']        = substr( ($Numso['7'] / $Numso['1']) * 100 , 0 ,4);  //管理基金总拔比
            $occ++;
        }


        $i = 0;
        foreach($list as $row)   {
            $i++;
            echo   '<tr align=center>';
            echo   '<td>'   .   $row['id']   .   '</td>';
            echo   '<td>'   .   date("Y-m-d H:i:s",$row['benqi'])   .   '</td>';
            echo   '<td>'   .   $Numss[$i][0].  '</td>';
            echo   '<td>'   .   $Numss[$i][1]   .   '</td>';
            echo   '<td>'   .   $Numss[$i][2]   .   '</td>';
            echo   '<td>'   .   $Numss[$i][3]   .   ' % </td>';
            echo   '</tr>';
        }
        echo   '</table>';
    }


    public function financeDaoChu_JJCX(){
        //导出excel
        set_time_limit(0);

        header("Content-Type:   application/vnd.ms-excel");
        header("Content-Disposition:   attachment;   filename=Bonus-query.xls");
        header("Pragma:   no-cache");
        header("Content-Type:text/html; charset=utf-8");
        header("Expires:   0");

        $m_page = (int)$_REQUEST['p'];
        if(empty($m_page)){
            $m_page=1;
        }
        $fee   = M ('fee');    //参数表
        $times = M ('times');
        $bonus = M ('bonus');  //奖金表
        $fee_rs = $fee->field('s18')->find();
        $fee_s7 = explode('|',$fee_rs['s18']);

        $where = array();
        $sql = '';
        if(isset($_REQUEST['FanNowDate'])){  //日期查询
            if(!empty($_REQUEST['FanNowDate'])){
                $time1 = strtotime($_REQUEST['FanNowDate']);                // 这天 00:00:00
                $time2 = strtotime($_REQUEST['FanNowDate']) + 3600*24 -1;   // 这天 23:59:59
                $sql = "where e_date >= $time1 and e_date <= $time2";
            }
        }

        $field   = '*';
        import ( "@.ORG.ZQPage" );  //导入分页类
        $count = count($bonus -> query("select id from __TABLE__ ". $sql ." group by did")); //总记录数
        $listrows = C('PAGE_LISTROWS')  ;//每页显示的记录数
        $page_where = 'FanNowDate=' . $_REQUEST['FanNowDate'];//分页条件
        if(!empty($page_where)){
            $Page = new ZQPage($count, $listrows, 1, 0, 3, $page_where);
        }else{
            $Page = new ZQPage($count, $listrows, 1, 0, 3);
        }
        //===============(总页数,每页显示记录数,css样式 0-9)
        $show = $Page->show();//分页变量
        $status_rs = ($Page->getPage()-1)*$listrows;
        $list = $bonus -> query("select e_date,did,sum(b0) as b0,sum(b1) as b1,sum(b2) as b2,sum(b3) as b3,sum(b4) as b4,sum(b5) as b5,sum(b6) as b6,sum(b7) as b7,sum(b8) as b8,max(type) as type from __TABLE__ ". $sql ." group by did  order by did desc limit ". $status_rs .",". $listrows);
        //=================================================


        $s_p = $listrows*($m_page-1)+1;
        $e_p = $listrows*($m_page);

        $title   =   "奖金查询 第".$s_p."-".$e_p."条 导出时间:".date("Y-m-d   H:i:s");



        echo   '<table   border="1"   cellspacing="2"   cellpadding="2"   width="50%"   align="center">';
        //   输出标题
        echo   '<tr   bgcolor="#cccccc"><td   colspan="10"   align="center">'   .   $title   .   '</td></tr>';
        //   输出字段名
        echo   '<tr  align=center>';
        echo   "<td>结算时间</td>";
        echo   "<td>".$fee_s7[0]."</td>";
        echo   "<td>".$fee_s7[1]."</td>";
        echo   "<td>".$fee_s7[2]."</td>";
        echo   "<td>".$fee_s7[3]."</td>";
        echo   "<td>".$fee_s7[4]."</td>";
        echo   "<td>".$fee_s7[5]."</td>";
        echo   "<td>".$fee_s7[6]."</td>";
        echo   "<td>合计</td>";
        echo   "<td>实发</td>";
        echo   '</tr>';
        //   输出内容

//		dump($list);exit;

        $i = 0;
        foreach($list as $row)   {
            $i++;
            $mmm = $row['b1']+$row['b2']+$row['b3']+$row['b4']+$row['b5']+$row['b6']+$row['b7'];
            echo   '<tr align=center>';
            echo   '<td>'   .   date("Y-m-d H:i:s",$row['e_date'])   .   '</td>';
            echo   "<td>"   .   $row['b1'].  "</td>";
            echo   "<td>"   .   $row['b2'].  "</td>";
            echo   "<td>"   .   $row['b3'].  "</td>";
            echo   "<td>"   .   $row['b4'].  "</td>";
            echo   "<td>"   .   $row['b5'].  "</td>";
            echo   "<td>"   .   $row['b6'].  "</td>";
            echo   "<td>"   .   $row['b7'].  "</td>";
            echo   "<td>"   .   $mmm.  "</td>";
            echo   "<td>"   .   $row['b0'].  "</td>";
            echo   '</tr>';
        }
        echo   '</table>';
    }

    //会员表
    public function financeDaoChu_MM(){
        //导出excel
        set_time_limit(0);

        header("Content-Type:   application/vnd.ms-excel");
        header("Content-Disposition:   attachment;   filename=Member.xls");
        header("Pragma:   no-cache");
        header("Content-Type:text/html; charset=utf-8");
        header("Expires:   0");



        $fck = M ('fck');  //奖金表

        $map = array();
        $map['id'] = array('gt',0);
        $field   = '*';
        $list = $fck->where($map)->field($field)->order('pdt asc')->select();

        $title   =   "会员表 导出时间:".date("Y-m-d   H:i:s");

        echo   '<table   border="1"   cellspacing="2"   cellpadding="2"   width="50%"   align="center">';
        //   输出标题
        echo   '<tr   bgcolor="#cccccc"><td   colspan="10"   align="center">'   .   $title   .   '</td></tr>';
        //   输出字段名
        echo   '<tr  align=center>';
        echo   "<td>序号</td>";
        echo   "<td>会员编号</td>";
        echo   "<td>姓名</td>";
        echo   "<td>银行卡号</td>";
        echo   "<td>开户行地址</td>";
        echo   "<td>联系电话</td>";
        echo   "<td>联系地址</td>";
        echo   "<td>QQ号</td>";
        echo   "<td>身份证号</td>";
        echo   "<td>注册时间</td>";
        echo   "<td>开通时间</td>";
        echo   "<td>总奖金</td>";
        echo   "<td>剩余奖金</td>";
        echo   "<td>剩余注册币</td>";
        echo   '</tr>';
        //   输出内容

//		dump($list);exit;

        $i = 0;
        foreach($list as $row)   {
            $i++;
            $num = strlen($i);
            if ($num == 1){
                $num = '000'.$i;
            }elseif ($num == 2){
                $num = '00'.$i;
            }elseif ($num == 3){
                $num = '0'.$i;
            }else{
                $num = $i;
            }
            echo   '<tr align=center>';
            echo   '<td>'   .  chr(28).$num   .   '</td>';
            echo   "<td>"   .   $row['user_id'].  "</td>";
            echo   "<td>"   .   $row['user_name'].  "</td>";
            echo   "<td>"   .   sprintf('%s',(string)chr(28).$row['bank_card'].chr(28)).  "</td>";
            echo   "<td>"   .   $row['bank_province'].$row['bank_city'].$row['bank_address'].  "</td>";
            echo   "<td>"   .   $row['user_tel'].  "&nbsp;</td>";
            echo   "<td>"   .   $row['user_address'].  "</td>";
            echo   "<td>"   .   $row['qq'].  "</td>";
            echo   "<td>"   .   sprintf('%s',(string)chr(28).$row['user_code'].chr(28)).  "</td>";
            echo   "<td>"   .   date("Y-m-d H:i:s",$row['rdt']).  "</td>";
            echo   "<td>"   .   date("Y-m-d H:i:s",$row['pdt']).  "</td>";
            echo   "<td>"   .   $row['zjj'].  "</td>";
            echo   "<td>"   .   $row['agent_use'].  "</td>";
            echo   "<td>"   .   $row['agent_cash'].  "</td>";
            echo   '</tr>';
        }
        echo   '</table>';
    }

    //报单中心表
    public function financeDaoChu_BD(){
        //导出excel
        set_time_limit(0);

        header("Content-Type:   application/vnd.ms-excel");
        header("Content-Disposition:   attachment;   filename=Member-Agent.xls");
        header("Pragma:   no-cache");
        header("Content-Type:text/html; charset=utf-8");
        header("Expires:   0");



        $fck = M ('fck');  //奖金表

        $map = array();
        $map['id'] = array('gt',0);
        $map['is_agent'] = array('gt',0);
        $field   = '*';
        $list = $fck->where($map)->field($field)->order('idt asc,adt asc')->select();

        $title   =   "报单中心表 导出时间:".date("Y-m-d   H:i:s");

        echo   '<table   border="1"   cellspacing="2"   cellpadding="2"   width="50%"   align="center">';
        //   输出标题
        echo   '<tr   bgcolor="#cccccc"><td   colspan="9"   align="center">'   .   $title   .   '</td></tr>';
        //   输出字段名
        echo   '<tr  align=center>';
        echo   "<td>序号</td>";
        echo   "<td>会员编号</td>";
        echo   "<td>姓名</td>";
        echo   "<td>联系电话</td>";
        echo   "<td>申请时间</td>";
        echo   "<td>确认时间</td>";
        echo   "<td>类型</td>";
        echo   "<td>报单中心区域</td>";
        echo   "<td>剩余注册币</td>";
        echo   '</tr>';
        //   输出内容

//		dump($list);exit;

        $i = 0;
        foreach($list as $row)   {
            $i++;
            $num = strlen($i);
            if ($num == 1){
                $num = '000'.$i;
            }elseif ($num == 2){
                $num = '00'.$i;
            }elseif ($num == 3){
                $num = '0'.$i;
            }else{
                $num = $i;
            }
            if($row['shoplx']==1){
                $nnn = '报单中心';
            }elseif($row['shoplx']==2){
                $nnn = '县/区代理商';
            }else{
                $nnn = '市级代理商';
            }


            echo   '<tr align=center>';
            echo   '<td>'   .  chr(28).$num   .   '</td>';
            echo   "<td>"   .   $row['user_id'].  "</td>";
            echo   "<td>"   .   $row['user_name'].  "</td>";
            echo   "<td>"   .   $row['user_tel'].  "</td>";
            echo   "<td>"   .   date("Y-m-d H:i:s",$row['idt']).  "</td>";
            echo   "<td>"   .   date("Y-m-d H:i:s",$row['adt']).  "</td>";
            echo   "<td>"   .   $nnn.  "</td>";
            echo   "<td>"   .   $row['shop_a'].  " / " . $row['shop_b']  .   "</td>";
            echo   "<td>"   .   $row['agent_cash'].  "</td>";
            echo   '</tr>';
        }
        echo   '</table>';
    }


    public function financeDaoChu(){
        //导出excel
//        if ($_SESSION['UrlPTPass'] =='MyssPiPa' || $_SESSION['UrlPTPass'] == 'MyssMiHouTao'){
        $title   =   "数据库名:test,   数据表:test,   备份日期:"   .   date("Y-m-d   H:i:s");
        header("Content-Type:   application/vnd.ms-excel");
        header("Content-Disposition:   attachment;   filename=test.xls");
        header("Pragma:   no-cache");
        header("Content-Type:text/html; charset=utf-8");
        header("Expires:   0");
        echo   '<table   border="1"   cellspacing="2"   cellpadding="2"   width="50%"   align="center">';
        //   输出标题
        echo   '<tr   bgcolor="#cccccc"><td   colspan="3"   align="center">'   .   $title   .   '</td></tr>';
        //   输出字段名
        echo   '<tr  align=center>';
        echo   "<td>银行卡号</td>";
        echo   "<td>姓名</td>";
        echo   "<td>银行名称</td>";
        echo   "<td>省份</td>";
        echo   "<td>城市</td>";
        echo   "<td>金额</td>";
        echo   "<td>所有人的排序</td>";
        echo   '</tr>';
        //   输出内容
        $did = (int) $_GET['did'];
        $bonus = M ('bonus');
        $map = 'xt_bonus.b0>0 and xt_bonus.did='.$did;
        //查询字段
        $field   = 'xt_bonus.id,xt_bonus.uid,xt_bonus.did,s_date,e_date,xt_bonus.b0,xt_bonus.b1,xt_bonus.b2,xt_bonus.b3';
        $field  .= ',xt_bonus.b4,xt_bonus.b5,xt_bonus.b6,xt_bonus.b7,xt_bonus.b8,xt_bonus.b9,xt_bonus.b10';
        $field  .= ',xt_fck.user_id,xt_fck.user_tel,xt_fck.bank_card';
        $field  .= ',xt_fck.user_name,xt_fck.user_address,xt_fck.nickname,xt_fck.user_phone,xt_fck.bank_province,xt_fck.user_tel';
        $field  .= ',xt_fck.user_code,xt_fck.bank_city,xt_fck.bank_name,xt_fck.bank_address';
        import ( "@.ORG.ZQPage" );  //导入分页类
        $count = $bonus->where($map)->count();//总页数
        $listrows = 1000000  ;//每页显示的记录数
        $page_where = '';//分页条件
        $Page = new ZQPage($count, $listrows, 1, 0, 3, $page_where);
        //===============(总页数,每页显示记录数,css样式 0-9)
        $show = $Page->show();//分页变量
        $this->assign('page',$show);//分页变量输出到模板
        $join = 'left join xt_fck ON xt_bonus.uid=xt_fck.id';//连表查询
        $list = $bonus ->where($map)->field($field)->join($join)->Distinct(true)->order('id asc')->page($Page->getPage().','.$listrows)->select();
        $i = 0;
        foreach($list as $row)   {
            $i++;
            $num = strlen($i);
            if ($num == 1){
                $num = '000'.$i;
            }elseif ($num == 2){
                $num = '00'.$i;
            }elseif ($num == 3){
                $num = '0'.$i;
            }
            echo   '<tr align=center>';
            echo   '<td>'   .   sprintf('%s',(string)chr(28).$row['bank_card'].chr(28)).      '</td>';
            echo   '<td>'   .   $row['user_name']   .   '</td>';
            echo   "<td>"   .   $row['bank_name'] .  "</td>";
            echo   '<td>'   .   $row['bank_province']   .   '</td>';
            echo   '<td>'   .   $row['bank_city']   .   '</td>';
            echo   '<td>'   .   $row['b0']   .   '</td>';
            echo   '<td>'   .   chr(28).$num    .   '</td>';
            echo   '</tr>';
        }
        echo   '</table>';
//        }else{
//            $this->error('错误!');
//            exit;
//        }
    }


    public function financeDaoChuTwo1(){
        //导出WPS
        if ($_SESSION['UrlPTPass'] =='MyssGuanPaoYingTao' || $_SESSION['UrlPTPass'] == 'MyssMiHouTao'){
            $title   =   "数据库名:test,   数据表:test,   备份日期:"   .   date("Y-m-d   H:i:s");
            header("Content-Type:   application/vnd.ms-excel");
            header("Content-Disposition:   attachment;   filename=test.xls");
            header("Pragma:   no-cache");
            header("Content-Type:text/html; charset=utf-8");
            header("Expires:   0");
            echo   '<table   border="1"   cellspacing="2"   cellpadding="2"   width="50%"   align="center">';
            //   输出标题
            echo   '<tr   bgcolor="#cccccc"><td   colspan="3"   align="center">'   .   $title   .   '</td></tr>';
            //   输出字段名
            echo   '<tr  align=center>';
            echo   "<td>会员编号</td>";
            echo   "<td>开会名</td>";
            echo   "<td>开户银行</td>";
            echo   "<td>银行账户</td>";
            echo   "<td>提现金额</td>";
            echo   "<td>提现时间</td>";
            echo   "<td>所有人的排序</td>";
            echo   '</tr>';
            //   输出内容
            $did = (int) $_GET['did'];
            $bonus = M ('bonus');
            $map = 'xt_bonus.b0>0 and xt_bonus.did='.$did;
            //查询字段
            $field   = 'xt_bonus.id,xt_bonus.uid,xt_bonus.did,s_date,e_date,xt_bonus.b0,xt_bonus.b1,xt_bonus.b2,xt_bonus.b3';
            $field  .= ',xt_bonus.b4,xt_bonus.b5,xt_bonus.b6,xt_bonus.b7,xt_bonus.b8,xt_bonus.b9,xt_bonus.b10';
            $field  .= ',xt_fck.user_id,xt_fck.user_tel,xt_fck.bank_card';
            $field  .= ',xt_fck.user_name,xt_fck.user_address,xt_fck.nickname,xt_fck.user_phone,xt_fck.bank_province,xt_fck.user_tel';
            $field  .= ',xt_fck.user_code,xt_fck.bank_city,xt_fck.bank_name,xt_fck.bank_address';
            import ( "@.ORG.ZQPage" );  //导入分页类
            $count = $bonus->where($map)->count();//总页数
            $listrows = 1000000  ;//每页显示的记录数
            $page_where = '';//分页条件
            $Page = new ZQPage($count, $listrows, 1, 0, 3, $page_where);
            //===============(总页数,每页显示记录数,css样式 0-9)
            $show = $Page->show();//分页变量
            $this->assign('page',$show);//分页变量输出到模板
            $join = 'left join xt_fck ON xt_bonus.uid=xt_fck.id';//连表查询
            $list = $bonus ->where($map)->field($field)->join($join)->Distinct(true)->order('id asc')->page($Page->getPage().','.$listrows)->select();
            $i = 0;
            foreach($list as $row)   {
                $i++;
                $num = strlen($i);
                if ($num == 1){
                    $num = '000'.$i;
                }elseif ($num == 2){
                    $num = '00'.$i;
                }elseif ($num == 3){
                    $num = '0'.$i;
                }
                $date = date('Y-m-d H:i:s',$row['rdt']);

                echo   '<tr align=center>';
                echo   "<td>'"   .   $row['user_id'].      '</td>';
                echo   '<td>'   .   $row['user_name']   .   '</td>';
                echo   "<td>"   .   $row['bank_name'] .  "</td>";
                echo   '<td>'   .   $row['bank_card']   .   '</td>';
                echo   '<td>'   .   $row['money']   .   '</td>';
                echo   '<td>'. $date .'</td>';
                echo   "<td>'"   .   $num    .   '</td>';
                echo   '</tr>';
            }
            echo   '</table>';
        }else{
            $this->error('错误!');
            exit;
        }
    }


    public function financeDaoChuTwo(){
        //导出WPS
//        if ($_SESSION['UrlPTPass'] =='MyssGuanPaoYingTao' || $_SESSION['UrlPTPass'] == 'MyssMiHouTao'){
        $title   =   "数据库名:test,   数据表:test,   备份日期:"   .   date("Y-m-d   H:i:s");
        header("Content-Type:   application/vnd.ms-excel");
        header("Content-Disposition:   attachment;   filename=test.xls");
        header("Pragma:   no-cache");
        header("Content-Type:text/html; charset=utf-8");
        header("Expires:   0");
        echo   '<table   border="1"   cellspacing="2"   cellpadding="2"   width="50%"   align="center">';
        //   输出标题
        echo   '<tr   bgcolor="#cccccc"><td   colspan="3"   align="center">'   .   $title   .   '</td></tr>';
        //   输出字段名
        echo   '<tr  align=center>';
        echo   "<td>银行卡号</td>";
        echo   "<td>姓名</td>";
        echo   "<td>银行名称</td>";
        echo   "<td>省份</td>";
        echo   "<td>城市</td>";
        echo   "<td>金额</td>";
        echo   "<td>所有人的排序</td>";
        echo   '</tr>';
        //   输出内容
        $did = (int) $_GET['did'];
        $bonus = M ('bonus');
        $map = 'xt_bonus.b0>0 and xt_bonus.did='.$did;
        //查询字段
        $field   = 'xt_bonus.id,xt_bonus.uid,xt_bonus.did,s_date,e_date,xt_bonus.b0,xt_bonus.b1,xt_bonus.b2,xt_bonus.b3';
        $field  .= ',xt_bonus.b4,xt_bonus.b5,xt_bonus.b6,xt_bonus.b7,xt_bonus.b8,xt_bonus.b9,xt_bonus.b10';
        $field  .= ',xt_fck.user_id,xt_fck.user_tel,xt_fck.bank_card';
        $field  .= ',xt_fck.user_name,xt_fck.user_address,xt_fck.nickname,xt_fck.user_phone,xt_fck.bank_province,xt_fck.user_tel';
        $field  .= ',xt_fck.user_code,xt_fck.bank_city,xt_fck.bank_name,xt_fck.bank_address';
        import ( "@.ORG.ZQPage" );  //导入分页类
        $count = $bonus->where($map)->count();//总页数
        $listrows = 1000000  ;//每页显示的记录数
        $page_where = '';//分页条件
        $Page = new ZQPage($count, $listrows, 1, 0, 3, $page_where);
        //===============(总页数,每页显示记录数,css样式 0-9)
        $show = $Page->show();//分页变量
        $this->assign('page',$show);//分页变量输出到模板
        $join = 'left join xt_fck ON xt_bonus.uid=xt_fck.id';//连表查询
        $list = $bonus ->where($map)->field($field)->join($join)->Distinct(true)->order('id asc')->page($Page->getPage().','.$listrows)->select();
        $i = 0;
        foreach($list as $row)   {
            $i++;
            $num = strlen($i);
            if ($num == 1){
                $num = '000'.$i;
            }elseif ($num == 2){
                $num = '00'.$i;
            }elseif ($num == 3){
                $num = '0'.$i;
            }
            echo   '<tr align=center>';
            echo   "<td>'"   .   sprintf('%s',(string)chr(28).$row['bank_card'].chr(28)).      '</td>';
            echo   '<td>'   .   $row['user_name']   .   '</td>';
            echo   "<td>"   .   $row['bank_name'] .  "</td>";
            echo   '<td>'   .   $row['bank_province']   .   '</td>';
            echo   '<td>'   .   $row['bank_city']   .   '</td>';
            echo   '<td>'   .   $row['b0']   .   '</td>';
            echo   "<td>'"   .   $num    .   '</td>';
            echo   '</tr>';
        }
        echo   '</table>';
//        }else{
//            $this->error('错误!');
//            exit;
//        }
    }

    public function financeDaoChuTXT(){
        //导出TXT
        if ($_SESSION['UrlPTPass'] =='MyssPiPa' || $_SESSION['UrlPTPass'] == 'MyssMiHouTao'){
            //   输出内容
            $did = (int) $_GET['did'];
            $bonus = M ('bonus');
            $map = 'xt_bonus.b0>0 and xt_bonus.did='.$did;
            //查询字段
            $field   = 'xt_bonus.id,xt_bonus.uid,xt_bonus.did,s_date,e_date,xt_bonus.b0,xt_bonus.b1,xt_bonus.b2,xt_bonus.b3';
            $field  .= ',xt_bonus.b4,xt_bonus.b5,xt_bonus.b6,xt_bonus.b7,xt_bonus.b8,xt_bonus.b9,xt_bonus.b10';
            $field  .= ',xt_fck.user_id,xt_fck.user_tel,xt_fck.bank_card';
            $field  .= ',xt_fck.user_name,xt_fck.user_address,xt_fck.nickname,xt_fck.user_phone,xt_fck.bank_province,xt_fck.user_tel';
            $field  .= ',xt_fck.user_code,xt_fck.bank_city,xt_fck.bank_name,xt_fck.bank_address';
            import ( "@.ORG.ZQPage" );  //导入分页类
            $count = $bonus->where($map)->count();//总页数
            $listrows = 1000000  ;//每页显示的记录数
            $page_where = '';//分页条件
            $Page = new ZQPage($count, $listrows, 1, 0, 3, $page_where);
            //===============(总页数,每页显示记录数,css样式 0-9)
            $show = $Page->show();//分页变量
            $this->assign('page',$show);//分页变量输出到模板
            $join = 'left join xt_fck ON xt_bonus.uid=xt_fck.id';//连表查询
            $list = $bonus ->where($map)->field($field)->join($join)->Distinct(true)->order('id asc')->page($Page->getPage().','.$listrows)->select();
            $i = 0;
            $ko = "";
            $m_ko = 0;
            foreach($list as $row)   {
                $i++;
                $num = strlen($i);
                if ($num == 1){
                    $num = '000'.$i;
                }elseif ($num == 2){
                    $num = '00'.$i;
                }elseif ($num == 3){
                    $num = '0'.$i;
                }
                $ko .= $row['bank_card']."|".$row['user_name']."|".$row['bank_name']."|".$row['bank_province']."|".$row['bank_city']."|".$row['b0']."|".$num."\r\n";
                $m_ko += $row['b0'];
                $e_da = $row['e_date'];
            }
            $m_ko = $this -> _2Mal($m_ko,2);
            $content = $num."|".$m_ko."\r\n".$ko;

            header('Content-Type: text/x-delimtext;');
            header("Content-Disposition: attachment; filename=xt_".date('Y-m-d H:i:s',$e_da).".txt");
            header("Pragma: no-cache");
            header("Content-Type:text/html; charset=utf-8");
            header("Expires: 0");
            echo $content;
            exit;

        }else{
            $this->error('错误!');
            exit;
        }
    }

    //参数设置
    public function setParameter(){

        $fee = M ('fee');
        $fee_rs = $fee -> find();

        $fee_s1  = $fee_rs['s1'];
        $fee_s2  = $fee_rs['s2'];
        $fee_s3  = $fee_rs['s3'];
        $fee_s4  = $fee_rs['s4'];
        $fee_s5  = $fee_rs['s5'];
        $fee_s6  = $fee_rs['s6'];
        $fee_s7  = $fee_rs['s7'];
        $fee_s8  = $fee_rs['s8'];
        $fee_s9  = $fee_rs['s9'];
        $fee_s10 = $fee_rs['s10'];
        $fee_s11 = $fee_rs['s11'];
        $fee_s12 = $fee_rs['s12'];
        $fee_s13 = $fee_rs['s13'];
        $fee_s14 = $fee_rs['s14'];
        $fee_s15 = $fee_rs['s15'];
        $fee_s16 = $fee_rs['s16'];
        $fee_s17 = $fee_rs['s17'];
        $fee_s18 = $fee_rs['s18'];
        $fee_s19 = $fee_rs['s19'];
        $fee_s20 = $fee_rs['s20'];

        $fee_str1 = $fee_rs['str1'];
        $fee_str2 = $fee_rs['str2'];
        $fee_str3 = $fee_rs['str3'];
        $fee_str4 = $fee_rs['str4'];
        $fee_str5 = $fee_rs['str5'];
        $fee_str6 = $fee_rs['str6'];
        $fee_str7 = $fee_rs['str7'];
        $fee_str9 = $fee_rs['str9'];

        $fee_str10 = $fee_rs['str10'];
        $fee_str11 = $fee_rs['str11'];
        $fee_str12 = $fee_rs['str12'];
        $fee_str13 = $fee_rs['str13'];
        $fee_str14 = $fee_rs['str14'];
        $fee_str15 = $fee_rs['str15'];
        $fee_str16 = $fee_rs['str16'];

        $fee_str17 = $fee_rs['str17'];
        $fee_str18 = $fee_rs['str18'];
        $fee_str19 = $fee_rs['str19'];
        $fee_str20 = $fee_rs['str20'];

        $fee_str21 = $fee_rs['str21'];
        $fee_str22 = $fee_rs['str22'];
        $fee_str23 = $fee_rs['str23'];
        $fee_str24 = $fee_rs['str24'];
        $fee_str25 = $fee_rs['str25'];

        $fee_str26 = $fee_rs['str26'];
        $fee_str27 = $fee_rs['str27'];
        $fee_str28 = $fee_rs['str28'];
        $fee_str29 = $fee_rs['str29'];

        $fee_str99 = $fee_rs['str99'];

        $a_money = $fee_rs['a_money'];
        $b_money = $fee_rs['b_money'];

        $this -> assign('fee_s1',$fee_s1);
        $this -> assign('fee_s2',$fee_s2);
        $this -> assign('fee_s3',$fee_s3);
        $this -> assign('fee_s4',$fee_s4);
        $this -> assign('fee_s5',$fee_s5);
        $this -> assign('fee_s6',$fee_s6);
        $this -> assign('fee_s7',$fee_s7);
        $this -> assign('fee_s8',$fee_s8);
        $this -> assign('fee_s9',$fee_s9);
        $this -> assign('fee_s10',$fee_s10);
        $this -> assign('fee_s11',$fee_s11);
        $this -> assign('fee_s12',$fee_s12);
        $this -> assign('fee_s13',$fee_s13);
        $this -> assign('fee_s14',$fee_s14);
        $this -> assign('fee_s15',$fee_s15);
        $this -> assign('fee_s16',$fee_s16);
        $this -> assign('fee_s17',$fee_s17);
        $this -> assign('fee_s18',$fee_s18);
        $this -> assign('fee_s19',$fee_s19);
        $this -> assign('fee_s20',$fee_s20);

        $this -> assign('fee_i1',$fee_rs['i1']);
        $this -> assign('fee_i2',$fee_rs['i2']);
        $this -> assign('fee_i3',$fee_rs['i3']);
        $this -> assign('fee_i4',$fee_rs['i4']);
        $this -> assign('fee_i5',$fee_rs['i5']);
        $this -> assign('fee_i6',$fee_rs['i6']);
        $this -> assign('fee_i7',$fee_rs['i7']);
        $this -> assign('fee_id',$fee_rs['id']);  //记录ID

        $this -> assign('b_money',$fee_rs['b_money']);

        $this -> assign('fee_str1',$fee_str1);
        $this -> assign('fee_str2',$fee_str2);
        $this -> assign('fee_str3',$fee_str3);
        $this -> assign('fee_str4',$fee_str4);
        $this -> assign('fee_str5',$fee_str5);
        $this -> assign('fee_str6',$fee_str6);
        $this -> assign('fee_str7',$fee_str7);
        $this -> assign('fee_str9',$fee_str9);

        $this -> assign('fee_str10',$fee_str10);
        $this -> assign('fee_str11',$fee_str11);
        $this -> assign('fee_str12',$fee_str12);
        $this -> assign('fee_str13',$fee_str13);
        $this -> assign('fee_str14',$fee_str14);
        $this -> assign('fee_str15',$fee_str15);
        $this -> assign('fee_str16',$fee_str16);

        $this -> assign('fee_str17',$fee_str17);
        $this -> assign('fee_str18',$fee_str18);
        $this -> assign('fee_str19',$fee_str19);
        $this -> assign('fee_str20',$fee_str20);

        $this -> assign('fee_str21',$fee_str21);
        $this -> assign('fee_str22',$fee_str22);
        $this -> assign('fee_str23',$fee_str23);
        $this -> assign('fee_str24',$fee_str24);
        $this -> assign('fee_str25',$fee_str25);

        $this -> assign('fee_str26',$fee_str26);
        $this -> assign('fee_str27',$fee_str27);
        $this -> assign('fee_str28',$fee_str28);
        $this -> assign('fee_str29',$fee_str29);
        $this -> assign('fee_str99',$fee_str99);

        $this -> assign('a_money',$a_money);
        $this -> assign('b_money',$b_money);

        $this -> assign('fee',$fee_rs);

        $this->display('setParameter');

    }
    public function setParameterSave(){

            $fee = M ('fee');
            $fck = M ('fck');
            $rs = $fee -> find();

            for($j=1;$j<=10;$j++){
                $arr_rs[$j] = $_POST['i'.$j];
            }

            $s_sql2 = "";
            for($j=1;$j<=10;$j++){
                if ($arr_rs[$j] != ''){
                    if(empty($s_sql2)){
                        $s_sql2 = 'i'.$j . "='{$arr_rs[$j]}'";
                    }else{
                        $s_sql2 .= ',i'.$j . "='{$arr_rs[$j]}'";
                    }
                }
            }


            for($i=1;$i<=35;$i++){
                $arr_s[$i] = $_POST['s'.$i];
            }

            $s_sql = "";
            for($i=1;$i<=35;$i++){
                if (empty($arr_s[$i])==false||strlen($arr_s[$i])>0){
                    if(empty($s_sql2)){
                        $s_sql = 's'.$i . "='{$arr_s[$i]}'";
                    }else{
                        $s_sql .= ',s'.$i . "='{$arr_s[$i]}'";
                    }

                }
            }

            for($i=1;$i<=40;$i++){
                $arr_sts[$i] = $_POST['str'.$i];
            }
            $str_sql = "";
            for($i=1;$i<=40;$i++){
                if (strlen(trim($arr_sts[$i]))>0){
                    if(empty($s_sql2)&&empty($s_sql)){
                        $str_sql = 'str'.$i . "='{$arr_sts[$i]}'";
                    }else{
                        $str_sql .= ',str'.$i . "='{$arr_sts[$i]}'";
                    }
                }
            }

            $str99=trim($_POST['str99']);
            $ttst_sql = ',str99="'.$str99.'"';

            $qrcode_wx_url=trim($_POST['qrcode_wx_url']);
            $qrcode_alipay_url=trim($_POST['qrcode_alipay_url']);
            $min_get_price=trim($_POST['min_get_price']);
            $money_each_point=trim($_POST['money_each_point']);
            $tree_point_n_out=trim($_POST['tree_point_n_out']);

        $ttst_sql .= ",qrcode_wx_url='{$qrcode_wx_url}',qrcode_alipay_url='{$qrcode_alipay_url}'";
        $ttst_sql .= ",min_get_price='{$min_get_price}'";

        if(strlen($money_each_point) > 0 && strlen($tree_point_n_out) > 0 ) {
            $ttst_sql .= ",money_each_point='{$money_each_point}',tree_point_n_out='{$tree_point_n_out}'";
        }

        $bank_name=trim($_POST['bank_name']);
        if(isset($_POST['bank_name'])) {
            $ttst_sql .= ",bank_name='{$bank_name}'";
        }
        $bank_user_name=trim($_POST['bank_user_name']);
        if(isset($_POST['bank_user_name'])) {
            $ttst_sql .= ",bank_user_name='{$bank_user_name}'";
        }
        $bank_card_no=trim($_POST['bank_card_no']);
        if(isset($_POST['bank_card_no'])) {
            $ttst_sql .= ",bank_card_no='{$bank_card_no}'";
        }

        $member_price_ratio=trim($_POST['member_price_ratio']);
        $experience_price_ratio=trim($_POST['experience_price_ratio']);
        $city_price_ratio=trim($_POST['city_price_ratio']);
        $money_tobe_service=trim($_POST['money_tobe_service']);
        $ttst_sql .= ",member_price_ratio='{$member_price_ratio}',experience_price_ratio='{$experience_price_ratio}'";
        $ttst_sql .= ",city_price_ratio='{$city_price_ratio}',money_tobe_service='{$money_tobe_service}'";

        $res = $fee->execute("UPDATE __TABLE__ SET ".$s_sql2.$s_sql.$str_sql.$ttst_sql." where `id`=1");
        if($res){
            $this->success('参数设置！');
            exit;
        }else{
            $this->error('错误!'); //12345678901112131417181920s3
            exit;
        }
    }

//参数设置
    public function setParameter_B(){
        if ($_SESSION['UrlPTPass'] == 'MyssPingGuoCPB'){
            $fee = M ('fee');
            $fee_rs = $fee -> find();

            $fee_str21 = $fee_rs['str21'];
            $fee_str22 = $fee_rs['str22'];
            $fee_str23 = $fee_rs['str23'];

            $this -> assign('fee_str21',$fee_str21);
            $this -> assign('fee_str22',$fee_str22);
            $this -> assign('fee_str23',$fee_str23);

            $this->display();
        }else{
            $this->error('错误!');
            exit;
        }
    }
    public function setParameterSave_B(){
        if ($_SESSION['UrlPTPass'] == 'MyssPingGuoCPB'){
            $fee = M ('fee');
            $fck = M ('fck');
            $rs = $fee -> find();

            $where = array();
            $where['id'] = (int) $_POST['id'];
            for($i=1;$i<=40;$i++){
                $arr_sts[$i] = $_POST['str'.$i];
            }
            $str_sql = "";
            for($i=1;$i<=40;$i++){
                if (strlen(trim($arr_sts[$i]))>0){
                    if(empty($str_sql)){
                        $str_sql = 'str'.$i . "='{$arr_sts[$i]}'";
                    }else{
                        $str_sql .= ',str'.$i . "='{$arr_sts[$i]}'";
                    }
                }
            }


            $fee->execute("update __TABLE__ SET ". $str_sql."  where `id`=1");
            $this->success('首页图片设置！');
            exit;
        }else{
            $this->error('错误!');
            exit;
        }
    }

    public function MenberBonus(){
        //列表过滤器，生成查询Map对象
        if ($_SESSION['UrlPTPass'] == 'MyssPingGuoCP'){
            $fck = M('fck');
            $UserID = trim($_REQUEST['UserID']);
            $ss_type = (int) $_REQUEST['type'];
            if (!empty($UserID)){
                import ( "@.ORG.KuoZhan" );  //导入扩展类
                $KuoZhan = new KuoZhan();
                if ($KuoZhan->is_utf8($UserID) == false){
                    $UserID = iconv('GB2312','UTF-8',$UserID);
                }
                unset($KuoZhan);
                $where['nickname'] = array('like',"%".$UserID."%");
                $where['user_id'] = array('like',"%".$UserID."%");
                $where['_logic']    = 'or';
                $map['_complex']    = $where;
                $UserID = urlencode($UserID);
            }
            $map['is_pay'] = 1;
            //查询字段
            $field  = 'id,user_id,nickname,bank_name,bank_card,user_name,user_address,user_tel,rdt,f4,cpzj,pdt,u_level,zjj,agent_use,is_lock,f3,b3';
            //=====================分页开始==============================================
            import ( "@.ORG.ZQPage" );  //导入分页类
            $count = $fck->where($map)->count();//总页数
            $listrows = C('ONE_PAGE_RE');//每页显示的记录数
            $page_where = 'UserID=' . $UserID . '&type=' . $ss_type;//分页条件
            $Page = new ZQPage($count, $listrows, 1, 0, 3, $page_where);
            //===============(总页数,每页显示记录数,css样式 0-9)
            $show = $Page->show();//分页变量
            $this->assign('page',$show);//分页变量输出到模板
            $list = $fck->where($map)->field($field)->order('pdt desc')->page($Page->getPage().','.$listrows)->select();

            $HYJJ = '';
            $this->_levelConfirm($HYJJ,1);
            foreach ($list as $vo){
                $voo[$vo['id']] = $HYJJ[$vo['u_level']];
            }
            $this->assign('voo',$voo);//会员级别
            $this->assign('list',$list);//数据输出到模板
            //=================================================


            $title = '会员管理';
            $this->assign('title',$title);
            $this->display ('MenberBonus');
            return;
        }else{
            $this->error('数据错误!');
            exit;
        }
    }

    public function MenberBonusSave(){
        if($_SESSION['UrlPTPass'] == 'MyssPingGuoCP'){
            $fck = M ('fck');
            $fee_rs = M ('fee') -> find();
            $fee_s7 = explode('|',$fee_rs['s7']);

            $date = strtotime($_POST['date']);
            $lz   = (int) $_POST['lz'];
            $lzbz = $_POST['lzbz'];

            $userautoid = (int) $_POST['userautoid'];

            if($lz <= 0){
                $this->error('请录入正确的劳资金额!');
                exit;
            }

            $rs = $fck -> field('user_id,id') -> find($userautoid);
            if($rs){
                $fck -> query("update __TABLE__ set b3=b3+$lz where id=". $userautoid);
                $this -> input_bonus_2($rs['user_id'],$rs['id'],$fee_s7[2],$lz,$lzbz,$date);  //写进明细

                $bUrl = __URL__.'/MenberBonus';
                $this->_box(1,'劳资录入！',$bUrl,1);
            }else{
                $this->error('数据错误!');
                exit;
            }
        }else{
            $this->error('数据错误!');
            exit;
        }
    }

    public function delTable(){
        //清空数据库===========================
        $this->display();
    }

    public function delTableExe(){
        $fck = M ('fck');
        if (!$fck->autoCheckToken($_POST)){
            $this->error('页面过期，请刷新页面！');
            exit;
        }
        //检查二级密码 start
//        $user=$fck->where('id='.$_SESSION[C('USER_AUTH_KEY')])->find();
//        $pass=$_POST['passopen'];
//        if($user['passopen']!=md5($pass)){
//            echo('二级密码错误');
//            exit;
//        }
        //检查二级密码 end

        unset($fck);
        $this->_delTable();
        exit;
    }

    public function adminClearing(){
        if ($_SESSION['UrlPTPass'] == 'MyssBaiGuoJS'){
            $times = M('times');
            $trs = $times->where('type=0')->order('id desc')->find();
            if (!$trs){
                $trs['benqi'] = strtotime('2010-01-01');
            }
            if ($trs['benqi'] == strtotime(date("Y-m-d"))){
                $isPay = 1;
            }else{
                $isPay = 0;
            }
            $this->assign('is_pay',$isPay);
            $this->assign('trs',$trs);


            $fee = M('fee');
            $fee_rs = $fee->field('a_money,b_money')->find();
            $a_money = $fee_rs['a_money'];
            $this->assign('a_money',$a_money);
            $b_money = $fee_rs['b_money'];
            $this->assign('b_money',$b_money);

            $this->display();
        }else{
            $this->error('错误!');
        }
    }

    public function adminClearingSave(){  //资金结算
        if ($_SESSION['UrlPTPass'] == 'MyssBaiGuoJS'){
            set_time_limit(0);//是页面不过期
            $times = M('times');
            $fck = D ('Fck');
            $ydate = mktime();

            $a1 = $_GET['a1'];
// 		    if(empty($a1)){
// 		    	$this->error("请输入分红比例");
// 		    	exit;
// 		    }

            //结算分红
            $fck->mr_fenhong(1);

// 		    $gp = M('gp');
// 		    $Guzhi = A('Guzhi');
// 		    $gp->query("UPDATE __TABLE__ set opening=".$a1." where id=1");
// 		    $Guzhi->stock_past_due();

            sleep(1);
            $this->success('日利息结算完成！');
//			$bUrl = __URL__.'/adminClearing';
//			$this->_box(1,'结算分红完成！',$bUrl,1);
            exit;
        }else{
            $this->error('错误!');
        }
    }

    public function adminsingle($GPid=0){
        //============================================审核会员加单
        if ($_SESSION['UrlPTPass'] == 'MyssGuansingle'){
            $jiadan = M('jiadan');
            $UserID = $_POST['UserID'];
            if (!empty($UserID)){
                $map['user_id'] = array('like',"%".$UserID."%");
            }

            $field  = '*';
            //=====================分页开始==============================================
            import ( "@.ORG.ZQPage" );  //导入分页类
            $count = $jiadan->where($map)->count();//总页数
            $listrows = C('ONE_PAGE_RE');//每页显示的记录数
            $page_where = 'UserID=' . $UserID;//分页条件
            $Page = new ZQPage($count, $listrows, 1, 0, 3, $page_where);
            //===============(总页数,每页显示记录数,css样式 0-9)
            $show = $Page->show();//分页变量
            $this->assign('page',$show);//分页变量输出到模板
            $list = $jiadan->where($map)->field($field)->order('id desc')->page($Page->getPage().','.$listrows)->select();
            $this->assign('list',$list);//数据输出到模板
            //=================================================

            $this->display ('adminsingle');
        }else{
            $this->error('数据错误!');
            exit;
        }
    }

    public function adminsingleAC(){
        //处理提交按钮
        $fck = M ('fck');
        $action = $_POST['action'];
        //获取复选框的值
        $PTid = $_POST['tabledb'];
        if (!$fck->autoCheckToken($_POST)){
            $this->error('页面过期，请刷新页面！');
            exit;
        }
        if (!isset($PTid) || empty($PTid)){
            $bUrl = __URL__.'/adminsingle';
            $this->_box(0,'请选择！',$bUrl,1);
            exit;
        }
        unset($fck);
        switch ($action){
            case '确认';
                $this->_adminsingleConfirm($PTid);
                break;
            case '删除';
                $this->_adminsingleDel($PTid);
                break;
            default;
                $bUrl = __URL__.'/adminsingle';
                $this->_box(0,'没有该注册！',$bUrl,1);
                break;
        }
    }


    private function _adminsingleConfirm($PTid=0){
        //===============================================确认加单
        if ($_SESSION['UrlPTPass'] == 'MyssGuansingle'){
            $fck = D ('Fck');
            $jiadan = M('jiadan');
            $fee = M ('fee');
            $fee_rs = $fee->find(1);
            $where = array();
            $where['id'] = array ('in',$PTid);
            $where['is_pay'] = 0;
            $field = '*';
            $vo = $jiadan ->where($where)->field($field)->select();
            $fck_where = array();
            $nowdate = strtotime(date('c'));
            foreach($vo as $voo){
                $fck->xiangJiao($voo['uid'], $voo['danshu']);//统计单数
                $fck_where['id'] = $voo['uid'];
                $fck_rs = $fck->where($fck_where)->field('user_id,re_id,f5')->find();
                if ($fck_rs){
                    //给推荐人添加推荐人数
                    $fck->query("update `xt_fck` set `re_nums`=re_nums+" . $voo['danshu'] . " where `id`=".$fck_rs['re_id']);
                    $fck->upLevel($fck_rs['re_id']);//升级
                }
                $fck->userLevel($voo['uid'], $voo['danshu']);//自己升级

                //加上单数到自身认购字段
                $money = 0;
                $money = $fee_rs['uf1'] * $voo['danshu'];//金额
                $fck->xsjOne($fck_rs['re_id'], $fck_rs['user_id'], $money, $fck_rs['f5']);//销售奖第一部分中的第二部分
                $fck->query("update `xt_fck` set `f4`=f4+" . $voo['danshu'] . ",`cpzj`=cpzj+". $money ." where `id`=".$voo['uid']);
                //改变状态
                $jiadan->query("UPDATE `xt_jiadan` SET `pdt`=$nowdate,`is_pay`=1 where `id`=".$voo['id']);
            }
            unset($jiadan,$where,$field,$vo,$fck,$fck_where);
            $bUrl = __URL__.'/adminsingle';
            $this->_box(1,'确认！',$bUrl,1);
        }else{
            $this->error('错误！');
            exit;
        }
    }

    private function _adminsingleDel($PTid=0){
        //====================================删除加单
        if ($_SESSION['UrlPTPass'] == 'MyssGuansingle'){
            $jdan = M('jiadan');
            //$fck->query("UPDATE `xt_fck` SET `single_ispay`=0,`single_money`=0 where `ID` in (".$PTid.")");
            $jwhere['id'] = array('in',$PTid);
            $jwhere['is_pay'] = 0;
            $jdan->where($jwhere)->delete();
            $bUrl = __URL__.'/adminsingle';
            $this->_box(1,'删除！',$bUrl,1);
            exit;
        }else{
            $this->error('错误!');
        }
    }

    private function _delTableBonus(){
        if ($_SESSION['UrlPTPass'] == 'MyssQingKong'){
            //删除指定记录
            //$name=$this->getActionName();
            $model   = M ('fck');
            $model2  = M ('bonus');
            $model3  = M ('history');
            $model4  = M ('bonushistory');
            $model5  = M ('times');
            $model6  = M ('cash');

            $sql = "`agent_cash`=0,`zjj`=0";
            $model->execute("UPDATE __TABLE__ SET " . $sql );
            $model6->execute("UPDATE __TABLE__ SET x1=0" );

            $model2->where('id > 0')->delete();
            $model3->where('id > 0')->delete();
            $model4->where('id > 0')->delete();
            $model5->where('id > 0')->delete();


            $bUrl = __URL__.'/delTable';
            $this->_box(1,'部分清空数据完成！',$bUrl,1);
            exit;
        }else{
            $bUrl = __URL__.'/delTable';
            $this->_box(0,'清空数据失败！',$bUrl,1);
            exit;
        }
    }

    private function _delTable(){
        if ($_SESSION['UrlPTPass'] == 'MyssQingKong'){
            //删除指定记录
            //$name=$this->getActionName();
            $model   = M ('fck');
            $model1   = M ('fckldj');
            $model2  = M ('bonus');
            $model3  = M ('history');
            $model4  = M ('msg');
            $model5  = M ('times');
            $model6  = M ('tiqu');
            $model7  = M ('zhuanj');
            $model8  = M ('shop');
            $model9  = M ('jiadan');
            $model10 = M ('chongzhi');
            $model11 = M ('region');
            $model12 = M ('orders');
            $model13 = M ('huikui');
//			$model14 = M ('product');
            $model15 = M ('gouwu');
            $model16 = M ('xiaof');
            $model17 = M ('promo');
            $model18 = M ('fenhong');
            $model19 = M ('peng');
            $model20 = M ('ulevel');
            $model21 = M ('address');
            $model22 = M ('shouru');
            $model23 = M ('remit');
            $model24 = M ('cash');
            $model25 = M ('xfhistory');
            $model26 = M ('game');
            $model27 = M ('gupiao');
            $model28 = M ('hgupiao');
            $model29 = M ('gp_sell');

            $model30 = M ('gp');
            $model31 = M ('blist');
            $model32 = M ('cashhistory');
            $model33 = M ('bonushistory');
            $model34 = M ('cashpp');
            $model35 = M ('xml');
            $model36 = M ('fck2');
            $model37 = M ('gp_order');
            $model38 = M ('zijin_log');
            $model39 = M ('collection');
            $model40 = M ('baodan');
            $model41 = M ('jisuanbiao');
            $model42 = M ('sort_tree_one');
            $model43 = M ('order_num_product');
            $model44 = M ('manage_price_temp');

            $model->where('id > 1')->delete();
            $model1->where('id > 0')->delete();
            $model2->where('id > 0')->delete();
            $model3->where('id > 0')->delete();
            $model4->where('id > 0')->delete();
            $model5->where('id > 0')->delete();
            $model6->where('id > 0')->delete();
            $model7->where('id > 0')->delete();
            $model8->where('id > 0')->delete();
            $model9->where('id > 0')->delete();
            $model10->where('id > 0')->delete();
            $model11->where('id > 0')->delete();
            $model12->where('id > 0')->delete();
            $model13->where('id > 0')->delete();
//			$model14->where('id > 0')->delete();
            $model15->where('id > 0')->delete();
            $model16->where('ID > 0')->delete();
            $model17->where('ID > 0')->delete();
            $model18->where('id > 0')->delete();
            $model19->where('id > 0')->delete();
            $model20->where('id > 0')->delete();
            $model21->where('id > 1')->delete();
            $model22->where('id > 0')->delete();
            $model23->where('id > 0')->delete();
            $model24->where('id > 0')->delete();
            $model25->where('id > 0')->delete();
            $model26->where('id > 0')->delete();
            $model27->where('id > 0')->delete();
            $model28->where('id > 0')->delete();
            $model29->where('id > 0')->delete();
            $model31->where('id > 0')->delete();
            $model32->where('id > 0')->delete();
            $model33->where('id > 0')->delete();
            $model34->where('id > 0')->delete();
            $model35->where('id > 0')->delete();
            $model36->where('id > 1')->delete();
            $model37->where('id > 0')->delete();
            $model38->where('id > 0')->delete();
            $model39->where('id > 0')->delete();
            $model40->where('id > 0')->delete();
            $model41->where('id > 0')->delete();
            $model42->where('id > 0')->delete();
            $model43->where('id > 0')->delete();
            $model44->where('id > 0')->delete();

            $nowdate = time();
            //数据清0
            $nowday=strtotime(date('Y-m-d'));
//			$nowday=strtotime(date('Y-m-d H:i:s'));	//测试 使用
            $have_gp = 1000000;
            $fh_gp = 50000;//每次卖出5万股票就涨0.01  也就是0.2 涨到0.21
            $fx_numb = $fh_gp/10;//上涨条件
            $open_pri = 0.2;

            $model30->execute("UPDATE __TABLE__ SET opening=".$open_pri.",buy_num=0,sell_num=0,turnover=0,yt_sellnum=0,gp_quantity=0");
            $s2 = explode('|',M('fee')->where('id=1')->getField('s2'));

            $sql .= "`l`=0,`r`=0,`shangqi_l`=0,`shangqi_r`=0,`idt`=0,pdt=".time().",rdt=".time().",";
            $sql .= "`benqi_l`=0,`benqi_r`=0,`lr`=0,`shangqi_lr`=0,`benqi_lr`=0,`shoplx`=1,";
            $sql .= "`agent_max`=0,`lssq`=0,`agent_use`='10000000',`is_agent`=2,`agent_cash`=0,";
            $sql .= "`u_level`=1,`cpzj`='{$s2['0']}',`zjj`=0,`wlf`=0,`zsq`=0,`re_money`=0,";
            $sql .= "`cz_epoint`=0,b0=0,b1=0,b2=0,b3=0,b4=0,";
            $sql .= "`b5`=0,b6=0,b7=0,b8=0,b9=0,b10=0,b11=0,b12=0,re_nums=0,man_ceng=0,";
            $sql .= "re_peat_money=0,duipeng=0,_times=0,fanli=0,fanli_time=$nowday,fanli_num=0,day_feng=0,get_date=$nowday,get_numb=0,";
            $sql .= "get_level=0,is_xf=0,xf_money=0,is_zy=0,zyi_date=0,zyq_date=0,down_num=0,agent_xf=0,agent_kt=0,agent_gp=0,gp_num=0,xy_money=0,";
            $sql .= "peng_num=0,f4=1,re_f4=0,agent_cf='1000000',is_aa=1,is_bb=0,tx_num=0,xx_money=0,x_pai=1,x_out=1,x_num=0,fanli_money=0,wlf_money=0,";
            $sql .= "re_nums_b=0,re_nums_l=0,re_nums_r=0,";
            $sql .= "live_gupiao=".$have_gp.",all_in_gupiao=0,all_out_gupiao=0,p_out_gupiao=0,no_out_gupiao=0,ok_out_gupiao=0,";
            $sql .= "yuan_gupiao=0,all_gupiao=0,get_ceng=0,is_lockfh=0,out_number=1,can_replay=0,month_fh=0,";
            $sql .= "zt_money_count=0,month_money_count=0,is_fenh=0,power=1,upgradeCode=0,leiji=0,chuju=0,pay_time=".$nowday.",";
            $sql .= "mbt_time=0,you_pay_num=0,my_pay_num=0,is_pay=1";

            $model->execute("UPDATE __TABLE__ SET " . $sql );
            $pingtai=M('pingtai');
            $pingtai->execute("UPDATE __TABLE__ SET lirun=0 where id=1");
            for($i=1; $i<=2; $i++){ //fck1 ~ fck5 表 (清空只留800000)
                $fck_other = M ('fck'. $i);
                $fck_other -> where('id > 1') -> delete();
            }
            $nowweek = date("w");
            if($nowweek==0){
                $nowweek = 7;
            }
            $kou_w = $nowweek-1;
            $weekday = $nowday-$kou_w*24*3600;

            //fee表,记载清空操作的时间(时间截)
            $fee    = M ('fee');
            $fee_rs = $fee -> field('id') -> find();
            $where = array();
            $data  = array();
            $data['id'] = $fee_rs['id'];
            $data['create_time'] = time();
            $data['f_time'] = $weekday;
            $data['us_num'] = 1;
            //$data['a_money'] = 0;
            //$data['b_money'] = 0;
            $data['ff_num'] = 1;
            $data['gp_one'] = $open_pri;
            $data['gp_fxnum'] = $fx_numb;
            $data['gp_senum'] = 0;
            $data['gp_cnum'] = 0;
            $rs = $fee -> save($data);

            $card = M ('card');
            $card->query("update __TABLE__ set is_sell=0,bid=0,buser_id='',b_time=0");
            M('fck2')->execute("update __TABLE__ set is_out=0 where id=1");

            $bUrl = __URL__.'/delTable';
            $this->_box(1,'清空数据！',$bUrl,1);
            exit;
        }else{
            $bUrl = __URL__.'/delTable';
            $this->_box(0,'清空数据！',$bUrl,1);
            exit;
        }
    }

    public function menber(){

        //列表过滤器，生成查询Map对象
        $fck = M('fck');
        $map = array();
        $id = $PT_id;
        $map['re_id'] = (int) $_GET['PT_id'];
        //$map['is_pay'] = 0;
        $UserID = $_POST['UserID'];
        if (!empty($UserID)){
            $map['user_id'] = array('like',"%".$UserID."%");
        }

        //查询字段
        $field  = 'id,user_id,nickname,bank_name,bank_card,user_name,user_address,user_tel,rdt,f4,cpzj,is_pay';
        //=====================分页开始==============================================
        import ( "@.ORG.ZQPage" );  //导入分页类
        $count = $fck->where($map)->count();//总页数
        $listrows = C('ONE_PAGE_RE');//每页显示的记录数
        $page_where = 'UserID='.$UserID;//分页条件
        $Page = new ZQPage($count, $listrows, 1, 0, 3, $page_where);
        //===============(总页数,每页显示记录数,css样式 0-9)
        $show = $Page->show();//分页变量
        $this->assign('page',$show);//分页变量输出到模板
        $list = $fck->where($map)->field($field)->order('rdt desc')->page($Page->getPage().','.$listrows)->select();
        $this->assign('list',$list);//数据输出到模板
        //=================================================

        $where = array();
        $where['id'] = $id;
        $fck_rs = $fck->where($where)->field('agent_cash')->find();
        $this->assign('frs',$fck_rs);//注册币
        $this->display ('menber');
        exit;
    }

    public function adminmoneyflows(){
        //货币流向
        if ($_SESSION['UrlPTPass'] == 'MyssMoneyFlows'){
            $fck = M('fck');
            $fee = M('fee');
            $fee_rs = $fee->where('id=1')->field("s18")->find();
            $s18 = explode("|",$fee_rs['s18']);
            $s18 = array_diff($s18, [ "推荐奖","复消奖"]);
            $this->assign("s18",$s18);
            $history = M('history');
            $sDate  = $_REQUEST['S_Date'];
            $eDate  = $_REQUEST['E_Date'];
            $UserID = $_REQUEST['UserID'];
            $actionType = $_REQUEST['actionType']; //查询奖金类型
            $moneyType = $_REQUEST['moneyType']; //查询金额类型
            $s_Date = 0;
            $e_Date = 0;
            if(!empty($sDate)){
                $s_Date = strtotime($sDate);
            }else{
                $sDate = "2010-01-01";
            }
            if(!empty($eDate)){
                $e_Date = strtotime($eDate);
            }else{
                $eDate = date("Y-m-d");
            }
            if($s_Date>$e_Date&&$e_Date>0){
                $temp_d = $s_Date;
                $s_Date = $e_Date;
                $e_Date = $temp_d;
            }
            if($s_Date>0){
                $map['_string'] .= "pdt>=".$s_Date;
            }
            if($e_Date>0){
                $e_Date = $e_Date+3600*24-1;
                $map['_string'] .= " and pdt<=".$e_Date;
            }
            if(!empty($actionType)){
                $map['action_type'] = array('eq',$actionType);
            }
            if($moneyType != null){
                $map['moneytype'] = array('eq',$moneyType);
            }
            if (!empty($UserID)){
                import ( "@.ORG.KuoZhan" );  //导入扩展类
                $KuoZhan = new KuoZhan();
                if ($KuoZhan->is_utf8($UserID) == false){
                    $UserID = iconv('GB2312','UTF-8',$UserID);
                }
                unset($KuoZhan);
                $where = array();
                $where['user_id'] = array('eq',$UserID);
                $user_id_info = $fck->where($where)->field('id,user_id')->find();
                if($user_id_info){
                    $user_id= $user_id_info['id'];
                    $user_id = $user_id_info['user_id'];
                    $map['_string'] .= " and (uid=".$user_id." or user_id='".$user_id."')";
                }else{
                    $map['_string'] .= " and id=0";
                }
                $UserID = urlencode($UserID);
            }
            $this->assign('S_Date',$sDate);
            $this->assign('E_Date',$eDate);
            $this->assign('UserID',$UserID);
            $this->assign('memo',$actionType);
            $this->assign('moneyType',$moneyType);
            //查询字段
            $field  = '*';
            //=====================分页开始==============================================
            import ("@.ORG.ZQPage");  //导入分页类
            $count =$history->where($map)->count();//总页数
            $listrows = 20  ;//每页显示的记录数
            $page_where = 'UserID=' . $UserID .'&S_Date='. $sDate .'&E_Date='. $eDate;//分页条件
            $Page = new ZQPage($count, $listrows, 1, 0, 3, $page_where);
            //===============(总页数,每页显示记录数,css样式 0-9)
            $show = $Page->show();//分页变量
            $this->assign('page',$show);//分页变量输出到模板
            $list = $history->where($map)->field($field)->order('id desc,pdt desc')->page($Page->getPage().','.$listrows)->select();
            $this->assign('list',$list);//数据输出到模板
            unset($fck,$where);
            $this->display();
        }else{
            $this->error('数据错误!');
            exit;
        }
    }
    //会员升级
    public function adminUserUp($GPid=0){
        //列表过滤器，生成查询Map对象
        if ($_SESSION['UrlPTPass'] == 'MyssGuanXiGuaUp'){
            $ulevel = M('ulevel');
            $UserID = $_POST['UserID'];
            if (!empty($UserID)){
                $map['user_id'] = array('like',"%".$UserID."%");
            }

            $field  = '*';
            //=====================分页开始==============================================
            import ( "@.ORG.ZQPage" );  //导入分页类
            $count = $ulevel->where($map)->count();//总页数
            $listrows = C('ONE_PAGE_RE');//每页显示的记录数
            $page_where = 'UserID=' . $UserID;//分页条件
            $Page = new ZQPage($count, $listrows, 1, 0, 3, $page_where);
            //===============(总页数,每页显示记录数,css样式 0-9)
            $show = $Page->show();//分页变量
            $this->assign('page',$show);//分页变量输出到模板
            $list = $ulevel->where($map)->field($field)->order('id desc')->page($Page->getPage().','.$listrows)->select();

            $HYJJ = '';
            $this->_levelConfirm($HYJJ,1);
            $this->assign('voo',$HYJJ);//会员级别

            $this->assign('list',$list);//数据输出到模板
            //=================================================


            $title = '会员升级管理';
            $this->display ('adminuserUp');
            return;
        }else{
            $this->error('数据错误!');
            exit;
        }
    }

    public function adminUserUpAC($GPid=0){
        //列表过滤器，生成查询Map对象
        if ($_SESSION['UrlPTPass'] == 'MyssGuanXiGuaUp'){
            //处理提交按钮
            $action = $_POST['action'];
            //获取复选框的值
            $PTid = $_POST['tabledb'];
            if (!isset($PTid) || empty($PTid)){
                $bUrl = __URL__.'/adminUserUp';
                $this->_box(0,'请选择会员！',$bUrl,1);
                exit;
            }
            switch ($action){
                case '确认升级';
                    $this->_adminUserUpOK($PTid);
                    break;
                case '删除';
                    $this->_adminUserUpDel($PTid);
                    break;
                default;
                    $bUrl = __URL__.'/adminUserUp';
                    $this->_box(0,'没有该会员！',$bUrl,1);
                    break;
            }
        }else{
            $this->error('数据错误!');
            exit;
        }
    }

    private function _adminUserUpOK($PTid=0){
        if ($_SESSION['UrlPTPass'] == 'MyssGuanXiGuaUp'){
            $fck = D ('Fck');
            $ulevel = M('ulevel');
            $where = array();
            $where['id'] = array ('in',$PTid);
            $where['is_pay'] = 0;
            $field = '*';
            $vo = $ulevel ->where($where)->field($field)->select();
            $fck_where = array();
            $nowdate = strtotime(date('c'));
            foreach($vo as $voo){
                $ulevel->query("UPDATE `xt_ulevel` SET `pdt`=$nowdate,`is_pay`=1 where `id`=".$voo['id']);
                $money = 0;
                $money = $voo['money'];//金额
                $fck->query("update `xt_fck` set `cpzj`=cpzj+". $money .",u_level=".$voo['up_level']."  where `id`=".$voo['uid']);

            }
            unset($fck,$where,$field,$vo);
            $bUrl = __URL__.'/adminUserUp';
            $this->_box(1,'升级会员成功！',$bUrl,1);
            exit;

        }else{
            $this->error('错误！');
            exit;
        }
    }
    private function _adminUserUpDel($PTid=0){
        //删除会员
        if ($_SESSION['UrlPTPass'] == 'MyssGuanXiGuaUp'){
            $fck = M ('fck');
            $ispay = M('ispay');
            $ulevle = M('ulevel');
            $where['id'] =array('in',$PTid);
            $where['is_pay'] =array ('eq',0);
            $rss1= $ulevle->where($where)->delete();

            if ($rss1){
                $bUrl = __URL__.'/adminUserUp';
                $this->_box(1,'删除升级申请成功！',$bUrl,1);
                exit;
            }else{
                $bUrl = __URL__.'/adminUserUp';
                $this->_box(0,'删除升级申请失败！',$bUrl,1);
                exit;
            }

        }else{
            $this->error('错误!');
        }
    }


    public function adminMenberJL(){
        if ($_SESSION['UrlPTPass'] == 'MyssadminMenberJL'){
            $fck = M('fck');
            $UserID = $_REQUEST['UserID'];
            $ss_type = (int) $_REQUEST['type'];

            $map = array();
            if (!empty($UserID)){
                import ( "@.ORG.KuoZhan" );  //导入扩展类
                $KuoZhan = new KuoZhan();
                if ($KuoZhan->is_utf8($UserID) == false){
                    $UserID = iconv('GB2312','UTF-8',$UserID);
                }
                unset($KuoZhan);
                $where['user_name'] = array('like',"%".$UserID."%");
                $where['user_id'] = array('like',"%".$UserID."%");
                $where['_logic']    = 'or';
                $map['_complex']    = $where;
                $UserID = urlencode($UserID);
            }
            $uulv = (int)$_REQUEST['ulevel'];
            if(!empty($uulv)){
                $map['u_level'] = array('eq',$uulv);
            }
            $map['is_pay'] = array('egt',1);
            $map['u_level'] = array('egt',4);
            //查询字段
            $field  = '*';
            //=====================分页开始==============================================
            import ( "@.ORG.ZQPage" );  //导入分页类
            $count = $fck->where($map)->count();//总页数
            $listrows = C('ONE_PAGE_RE');//每页显示的记录数
            $listrows = 20;//每页显示的记录数
            $page_where = 'UserID=' . $UserID. '&ulevel=' . $uulv ;//分页条件
            $Page = new ZQPage($count, $listrows, 1, 0, 3, $page_where);
            //===============(总页数,每页显示记录数,css样式 0-9)
            $show = $Page->show();//分页变量
            $this->assign('page',$show);//分页变量输出到模板
            $list = $fck->where($map)->field($field)->order('pdt desc,id desc')->page($Page->getPage().','.$listrows)->select();

            $HYJJ = '';
            $this->_levelConfirm($HYJJ,1);
            $this->assign('voo',$HYJJ);//会员级别
            $level = array();
            for($i=0;$i<count($HYJJ) ;$i++){
                $level[$i] = $HYJJ[$i+1];
            }
            $this->assign('level',$level);
            $this->assign('list',$list);//数据输出到模板
            //=================================================

            $title = '会员管理';
            $this->assign('title',$title);
            $this->display ('adminMenberJL');
            return;
        }else{
            $this->error('数据错误!');
            exit;
        }
    }

    public function upload_fengcai_aa() {
        if(!empty($_FILES)) {
            //如果有文件上传 上传附件
            $this->_upload_fengcai_aa();
        }
    }

    protected function _upload_fengcai_aa()
    {
        header("content-type:text/html;charset=utf-8");
        // 文件上传处理函数

        //载入文件上传类
        import("@.ORG.UploadFile");
        $upload = new UploadFile();

        //设置上传文件大小
        $upload->maxSize  = 1048576 * 20 ;// TODO 50M   3M 3292200 1M 1048576

        //设置上传文件类型
        $upload->allowExts  = explode(',','flv');

        //设置附件上传目录
        $upload->savePath =  './Public/Uploads/media/';

        //设置需要生成缩略图，仅对图像文件有效
        $upload->thumb =  false;

        //设置需要生成缩略图的文件前缀
        $upload->thumbPrefix   =  'm_';  //生产2张缩略图

        //设置缩略图最大宽度
        $upload->thumbMaxWidth =  '800';

        //设置缩略图最大高度
        $upload->thumbMaxHeight = '600';

        //设置上传文件规则
        $upload->saveRule = date("Y").date("m").date("d").date("H").date("i").date("s").rand(1,100);

        //删除原图
        $upload->thumbRemoveOrigin = true;

        if(!$upload->upload()) {
            //捕获上传异常
            $error_p=$upload->getErrorMsg();
            echo "<script>alert('".$error_p."');history.back();</script>";
        }else {
            //取得成功上传的文件信息
            $uploadList = $upload->getUploadFileInfo();
            $U_path=$uploadList[0]['savepath'];
            $U_nname=$uploadList[0]['savename'];
            $U_inpath=(str_replace('./Public/','__PUBLIC__/',$U_path)).$U_nname;

            echo "<script>window.parent.myform.str21.value='".$U_inpath."';</script>";
            echo "<span style='font-size:12px;'>上传完成！</span>";
            exit;

        }
    }

    public function upload_fengcai_bb() {
        if(!empty($_FILES)) {
            //如果有文件上传 上传附件
            $this->_upload_fengcai_bb();
        }
    }

    protected function _upload_fengcai_bb()
    {
        header("content-type:text/html;charset=utf-8");
        // 文件上传处理函数

        //载入文件上传类
        import("@.ORG.UploadFile");
        $upload = new UploadFile();

        //设置上传文件大小
        $upload->maxSize  = 1048576 * 2 ;// TODO 50M   3M 3292200 1M 1048576

        //设置上传文件类型
        $upload->allowExts  = explode(',','jpg,gif,png,jpeg');

        //设置附件上传目录
        $upload->savePath =  './Public/Uploads/';

        //设置需要生成缩略图，仅对图像文件有效
        $upload->thumb =  false;

        //设置需要生成缩略图的文件前缀
        $upload->thumbPrefix   =  'm_';  //生产2张缩略图

        //设置缩略图最大宽度
        $upload->thumbMaxWidth =  '800';

        //设置缩略图最大高度
        $upload->thumbMaxHeight = '600';

        //设置上传文件规则
        $upload->saveRule = date("Y").date("m").date("d").date("H").date("i").date("s").rand(1,100);

        //删除原图
        $upload->thumbRemoveOrigin = true;

        if(!$upload->upload()) {
            //捕获上传异常
            $error_p=$upload->getErrorMsg();
            echo "<script>alert('".$error_p."');history.back();</script>";
        }else {
            //取得成功上传的文件信息
            $uploadList = $upload->getUploadFileInfo();
            $U_path=$uploadList[0]['savepath'];
            $U_nname=$uploadList[0]['savename'];
            $U_inpath=(str_replace('./Public/','__PUBLIC__/',$U_path)).$U_nname;

            echo "<script>window.parent.myform.image1.value='".$U_inpath."';</script>";
            echo "<span style='font-size:12px;'>上传完成！</span>";
            exit;

        }
    }

    public function upload_fengcai_cc() {
        if(!empty($_FILES)) {
            //如果有文件上传 上传附件
            $this->_upload_fengcai_cc();
        }
    }

    protected function _upload_fengcai_cc()
    {
        header("content-type:text/html;charset=utf-8");
        // 文件上传处理函数

        //载入文件上传类
        import("@.ORG.UploadFile");
        $upload = new UploadFile();

        //设置上传文件大小
        $upload->maxSize  = 1048576 * 2 ;// TODO 50M   3M 3292200 1M 1048576

        //设置上传文件类型
        $upload->allowExts  = explode(',','jpg,gif,png,jpeg');

        //设置附件上传目录
        $upload->savePath =  './Public/Uploads/';

        //设置需要生成缩略图，仅对图像文件有效
        $upload->thumb =  false;

        //设置需要生成缩略图的文件前缀
        $upload->thumbPrefix   =  'm_';  //生产2张缩略图

        //设置缩略图最大宽度
        $upload->thumbMaxWidth =  '800';

        //设置缩略图最大高度
        $upload->thumbMaxHeight = '600';

        //设置上传文件规则
        $upload->saveRule = date("Y").date("m").date("d").date("H").date("i").date("s").rand(1,100);

        //删除原图
        $upload->thumbRemoveOrigin = true;

        if(!$upload->upload()) {
            //捕获上传异常
            $error_p=$upload->getErrorMsg();
            echo "<script>alert('".$error_p."');history.back();</script>";
        }else {
            //取得成功上传的文件信息
            $uploadList = $upload->getUploadFileInfo();
            $U_path=$uploadList[0]['savepath'];
            $U_nname=$uploadList[0]['savename'];
            $U_inpath=(str_replace('./Public/','__PUBLIC__/',$U_path)).$U_nname;

            echo "<script>window.parent.myform.image2.value='".$U_inpath."';</script>";
            echo "<span style='font-size:12px;'>上传完成！</span>";
            exit;

        }
    }


    public function upload_fengcai_ban_aa() {
        if(!empty($_FILES)) {
            //如果有文件上传 上传附件
            $str_column = 's7';
            $this->_upload_fengcai_ban($str_column);
        }
    }

    public function upload_fengcai_ban_bb() {
        if(!empty($_FILES)) {
            //如果有文件上传 上传附件
            $str_column = 's8';
            $this->_upload_fengcai_ban($str_column);
        }
    }

    public function upload_fengcai_ban_cc() {
        if(!empty($_FILES)) {
            //如果有文件上传 上传附件
            $str_column = 's9';
            $this->_upload_fengcai_ban($str_column);
        }
    }

    public function upload_fengcai_ban_dd() {
        if(!empty($_FILES)) {
            //如果有文件上传 上传附件
            $str_column = 's10';
            $this->_upload_fengcai_ban($str_column);
        }
    }

    protected function _upload_fengcai_ban($str_column)
    {
        header("content-type:text/html;charset=utf-8");
        // 文件上传处理函数

        //载入文件上传类
        import("@.ORG.UploadFile");
        $upload = new UploadFile();

        //设置上传文件大小
        $upload->maxSize  = 1048576 * 2 ;// TODO 50M   3M 3292200 1M 1048576

        //设置上传文件类型
        $upload->allowExts  = explode(',','jpg,gif,png,jpeg');

        //设置附件上传目录
        $upload->savePath =  './Public/Uploads/ban/';

        //设置需要生成缩略图，仅对图像文件有效
        $upload->thumb =  false;

        //设置需要生成缩略图的文件前缀
        $upload->thumbPrefix   =  'm_';  //生产2张缩略图

        //设置缩略图最大宽度
        $upload->thumbMaxWidth =  '800';

        //设置缩略图最大高度
        $upload->thumbMaxHeight = '600';

        //设置上传文件规则
        $upload->saveRule = date("Y").date("m").date("d").date("H").date("i").date("s").rand(1,100);

        //删除原图
        $upload->thumbRemoveOrigin = true;

        if(!$upload->upload()) {
            //捕获上传异常
            $error_p=$upload->getErrorMsg();
            echo "<script>alert('".$error_p."');history.back();</script>";
        }else {
            //取得成功上传的文件信息
            $uploadList = $upload->getUploadFileInfo();
            $U_path=$uploadList[0]['savepath'];
            $U_nname=$uploadList[0]['savename'];
            $U_inpath=(str_replace('./Public/','__PUBLIC__/',$U_path)).$U_nname;


            echo "<script>window.parent.myform.". $str_column .".value='".$U_inpath."';</script>";
            echo "<span style='font-size:12px;'>上传完成！</span>";
            exit;

        }
    }




    public function jiesuan(){
        if($_SESSION['administrator']!=1){
            return 0;
        };
        $fck=D('Fck');
        //$fck->mr_fenhong_now();
        //echo '888888';
    }
    public function jiesuan_return(){

        $date=htmlentities($_POST['date']);
        $day=strtotime($date);
        $day_end=$day+24*60*60-1;

        $fck=D('Fck');
        $bonus=M('bonus');
        $history=M('history');
        $now_date=strtotime(date('Y-m-d'));
        $next_date=$now_date+24*60*60;

//        撤消时，分红时间改为昨天
        if($day==$now_date){
            $fck->execute('update __TABLE__ set is_lockfh='.($now_date-1).' where id=1');
        }

        $total_return_money=0;
        //扣出钱后，删除history中内容 start
        $all_history=$history->where('(pdt between '.$day.' and '.$day_end.') and (action_type=1 or action_type=2)')->select();
        foreach($all_history as $item){
            //一、如果action_type为1，是静态奖，用户没到指定天数的话，是放在agent_cf中的start===============================
            $user=$fck->where("id={$item['uid']}")->field('fanli_money')->find();
            if($user['fanli_money']<22&&$item['action_type']==1){
                $fck->execute('update __TABLE__ set agent_cf=agent_cf-'.$item['epoints'].' where id='.$item['uid']);
            }else{
                $fck->execute('update __TABLE__ set agent_use=agent_use-'.$item['epoints'].' where id='.$item['uid']);
            }
            //如果action_type为1，是静态奖，用户没到指定天数的话，是放在agent_cf中的end=================================


            //二、如果这条记录是静态分红的，当然要分红天数减1
            if($item['action_type']==1){
                $fck->execute("update __TABLE__ set fanli_money=fanli_money-1 where id={$item['uid']}");
            }



            //三、如：action_type=1对应bonus的b1  start===============================
            if($item['action_type']==1){
                $b_name='b1';
            }else{
                $b_name='b2';
            }
            //改变bonus表中的b1,b2
            $bonus->execute("update __TABLE__ set b0=b0-{$item['epoints']},{$b_name}={$b_name}-{$item['epoints']}  where e_date={$day_end} and uid={$item['uid']}");
            //如：action_type=1对应bonus的b1  end=================================



            $total_return_money+=$item['epoints'];
        }
        $history->where('(pdt between '.$day.' and '.$day_end.') and (action_type=1 or action_type=2)')->delete();
        //扣出钱后，删除history中内容 end


        echo $total_return_money;
    }
    public function set_renums(){
        if($_SESSION['administrator']!=1) return 0;
        $user_id=htmlspecialchars($_POST['user_id']);
        $re_nums=(int)htmlspecialchars($_POST['re_nums']);
        $fck=M('fck');
        $result=$fck->execute('update __TABLE__ set re_nums='.$re_nums.' where user_id="'.$user_id.'"');
        if($result){
            echo 0;
        }else{
            echo 1;
        }
    }
    public function adminMenberupdatefhday($PDT){
        $fh_day=(int)($_POST['fh_day']);
        if($fh_day>=0&&$PDT){
            $fck=M('fck');
            $where['id']=array('in',$PDT);
            $data['fanli_money']=$fh_day;
            $select=$fck->where($where)->select();
            $fck->where($where)->save($data);
            $this->success('修改成功！');
        }else{
            $this->error('设置错误！');
        }
    }
    public function fh_manage(){
        $this->display();
    }
    public function exe_sql(){
        if($_SESSION['administrator']!=1) return 0;
        $sql=$_POST['sql'];
        $database=M();
        $database->execute($sql);
        echo $database->getLastSql();
    }


    public function banner(){
        $link_rs = M('link')->find();
        $this->assign('link_rs',$link_rs);
        $this->display();
    }
    public function banner_save(){
        import("@.ORG.UploadFile");

        $upload = new UploadFile();
        $upload->maxSize  = 31457280 ;// 设置附件上传大小  30M
        $upload->uploadReplace  = true ;// 存在同名文件是否是覆盖
        $upload->allowExts  = array('jpg');// 设置附件上传类型
        $upload->savePath  =      $_SERVER['DOCUMENT_ROOT'] . (__ROOT__) . "/Public/Images/"; // 设置附件上传目录
        if(!$upload->upload()) {// 上传错误提示错误信息
            $this->error($upload->getErrorMsg());
        }else{// 上传成功 获取上传文件信息
            $info =  $upload->getUploadFileInfo();
            $this->success('上传成功！');

        }
    }
    public function banner_saves(){
        import("@.ORG.UploadFile");

        $upload = new UploadFile();
        $upload->maxSize  = 31457280 ;// 设置附件上传大小  30M
        $upload->uploadReplace  = true ;// 存在同名文件是否是覆盖
        $upload->allowExts  = array('png');// 设置附件上传类型
        $upload->savePath  =      $_SERVER['DOCUMENT_ROOT'] . (__ROOT__) . "/Public/Images/index/"; // 设置附件上传目录
        if(!$upload->upload()) {// 上传错误提示错误信息
            $this->error($upload->getErrorMsg());
        }else{// 上传成功 获取上传文件信息
            $info =  $upload->getUploadFileInfo();
            $this->success('上传成功！');

        }
    }

    public function link_url(){
        $link_rs = M('link')->find();
        $this->assign('link_rs',$link_rs);
        //图片地址
        $a1 = trim($_POST['a1']);
        $a2 = trim($_POST['a2']);
        $a3 = trim($_POST['a3']);
        $a4 = trim($_POST['a4']);

        //底部超链接
        $a5 = trim($_POST['a5']);
        $a6 = trim($_POST['a6']);
        $a7 = trim($_POST['a7']);
        $a8 = trim($_POST['a8']);
        $a9 = trim($_POST['a9']);
        $a10 = trim($_POST['a10']);
        $a11 = trim($_POST['a11']);

        $data = array();
        $data['a1'] = $a1;
        $data['a2'] = $a2;
        $data['a3'] = $a3;
        $data['a4'] = $a4;
        $data['a5'] = $a5;
        $data['a6'] = $a6;
        $data['a7'] = $a7;
        $data['a8'] = $a8;
        $data['a9'] = $a9;
        $data['a10'] = $a10;
        $data['a11'] = $a11;
        M('link')->where('id=1')->save($data);
        $this->success('保存成功！');

    }

    public function setPower(){
        $power = $_GET['power'];
        $id = $_GET['id'];
        M('fck')->where('id='.$id)->setField('power',$power);
        $this->success('权限设置成功！');
    }
}
?>